From 64c94da8dcd883c71dfbb6feeaaf5fac9fcc3264 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Tue, 7 Mar 2023 17:25:47 +0900 Subject: [PATCH] display: backlight: Relocate display_backlight_change_brightness_by_dpms_state() to reduce plugin duplication Remove and redefine backlight_transit_state function in backlight_ops. This function is added to below display-backlight. int display_backlight_change_brightness_by_dpms_state(enum dpms_state state) -> In AOD mode, this function changes brightness smoothly. Change-Id: Iee3e16ad023fc71a3d1fccbf96dcabfbc156401c Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 4 +-- plugins/iot-headed/display/device-interface.c | 42 +------------------------ plugins/mobile/display/core.c | 4 +-- plugins/mobile/display/device-interface.c | 42 +------------------------ plugins/tv/display/core.c | 4 +-- plugins/tv/display/device-interface.c | 42 +------------------------ plugins/wearable/display/core.c | 4 +-- plugins/wearable/display/display-handler.c | 5 +-- src/display/display-backlight.c | 44 +++++++++++++++++++++++++++ src/display/display-backlight.h | 3 ++ 10 files changed, 61 insertions(+), 133 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 30bf606..5d637b8 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -299,7 +299,7 @@ static gboolean late_transit_on(void *data) g_source_remove(transit_timer); transit_timer = 0; - backlight_ops->transit_state(DPMS_ON); + display_backlight_change_brightness_by_dpms_state(DPMS_ON); return G_SOURCE_REMOVE; } @@ -425,7 +425,7 @@ inline void lcd_off_procedure(enum device_flags flag) } if (flags & LCD_PHASED_TRANSIT_MODE) - backlight_ops->transit_state(DPMS_OFF); + display_backlight_change_brightness_by_dpms_state(DPMS_OFF); SYS_G_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index 6f68ec7..b79cfca 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -91,51 +91,11 @@ bool display_dimstay_check(void) return false; } -/* It was operated only AOD enter & leave */ -static int backlight_transit_state(int state) -{ - int brt, val; - int start, end; - int default_brightness = 0; - - display_backlight_get_default_brightness(&default_brightness); - - display_backlight_get_brightness(&brt); - - if (state == DPMS_OFF) { - start = brt; - end = display_conf->aod_enter_level; - - /* - * The value of display_backlight_get_brightness is system brightness. - * But when device is LBM, the value is not same with real brightness. - * So it should be read exactly value for transit smooth effect - */ - display_backlight_get_brightness(&val); - - if (val > display_conf->aod_enter_level) - display_backlight_change_brightness(start, end, display_conf->brightness_change_step); - } else { - /* prevent transit effect when another effect is already executed */ - if (brt != display_conf->aod_enter_level) { - _W("effect is already executed brt(%d) aod_level(%d)", - brt, display_conf->aod_enter_level); - return 0; - } - - start = display_conf->aod_enter_level; - end = default_brightness; - display_backlight_change_brightness(start, end, display_conf->brightness_change_step); - } - - return 0; -} - static struct _backlight_ops backlight_ops = { .get_lcd_power = dpms_get_cached_state, .set_brightness = NULL, .get_brightness = NULL, - .transit_state = backlight_transit_state, + .transit_state = NULL, .transit_brt = NULL, }; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 398e68b..c8d64d6 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -306,7 +306,7 @@ static gboolean late_transit_on(void *data) g_source_remove(transit_timer); transit_timer = 0; - backlight_ops->transit_state(DPMS_ON); + display_backlight_change_brightness_by_dpms_state(DPMS_ON); return G_SOURCE_REMOVE; } @@ -432,7 +432,7 @@ inline void lcd_off_procedure(enum device_flags flag) } if (flags & LCD_PHASED_TRANSIT_MODE) - backlight_ops->transit_state(DPMS_OFF); + display_backlight_change_brightness_by_dpms_state(DPMS_OFF); SYS_G_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index b92bdcd..e2ca8a4 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -90,51 +90,11 @@ bool display_dimstay_check(void) return false; } -/* It was operated only AOD enter & leave */ -static int backlight_transit_state(int state) -{ - int brt, val; - int start, end; - int default_brightness = 0; - - display_backlight_get_default_brightness(&default_brightness); - - display_backlight_get_brightness(&brt); - - if (state == DPMS_OFF) { - start = brt; - end = display_conf->aod_enter_level; - - /* - * The value of display_backlight_get_brightness is system brightness. - * But when device is LBM, the value is not same with real brightness. - * So it should be read exactly value for transit smooth effect - */ - display_backlight_get_brightness(&val); - - if (val > display_conf->aod_enter_level) - display_backlight_change_brightness(start, end, display_conf->brightness_change_step); - } else { - /* prevent transit effect when another effect is already executed */ - if (brt != display_conf->aod_enter_level) { - _W("effect is already executed brt(%d) aod_level(%d)", - brt, display_conf->aod_enter_level); - return 0; - } - - start = display_conf->aod_enter_level; - end = default_brightness; - display_backlight_change_brightness(start, end, display_conf->brightness_change_step); - } - - return 0; -} - static struct _backlight_ops backlight_ops = { .get_lcd_power = dpms_get_cached_state, .set_brightness = NULL, .get_brightness = NULL, - .transit_state = backlight_transit_state, + .transit_state = NULL, .transit_brt = NULL, }; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index d434bd4..e7b7ca5 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -299,7 +299,7 @@ static gboolean late_transit_on(void *data) g_source_remove(transit_timer); transit_timer = 0; - backlight_ops->transit_state(DPMS_ON); + display_backlight_change_brightness_by_dpms_state(DPMS_ON); return G_SOURCE_REMOVE; } @@ -425,7 +425,7 @@ inline void lcd_off_procedure(enum device_flags flag) } if (flags & LCD_PHASED_TRANSIT_MODE) - backlight_ops->transit_state(DPMS_OFF); + display_backlight_change_brightness_by_dpms_state(DPMS_OFF); SYS_G_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 1756de5..e8eb6e4 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -91,51 +91,11 @@ bool display_dimstay_check(void) return false; } -/* It was operated only AOD enter & leave */ -static int backlight_transit_state(int state) -{ - int brt, val; - int start, end; - int default_brightness = 0; - - display_backlight_get_default_brightness(&default_brightness); - - display_backlight_get_brightness(&brt); - - if (state == DPMS_OFF) { - start = brt; - end = display_conf->aod_enter_level; - - /* - * The value of display_backlight_get_brightness is system brightness. - * But when device is LBM, the value is not same with real brightness. - * So it should be read exactly value for transit smooth effect - */ - display_backlight_get_brightness(&val); - - if (val > display_conf->aod_enter_level) - display_backlight_change_brightness(start, end, display_conf->brightness_change_step); - } else { - /* prevent transit effect when another effect is already executed */ - if (brt != display_conf->aod_enter_level) { - _W("effect is already executed brt(%d) aod_level(%d)", - brt, display_conf->aod_enter_level); - return 0; - } - - start = display_conf->aod_enter_level; - end = default_brightness; - display_backlight_change_brightness(start, end, display_conf->brightness_change_step); - } - - return 0; -} - static struct _backlight_ops backlight_ops = { .get_lcd_power = dpms_get_cached_state, .set_brightness = NULL, .get_brightness = NULL, - .transit_state = backlight_transit_state, + .transit_state = NULL, .transit_brt = NULL, }; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index c62c3db..adcb55b 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -509,7 +509,7 @@ static gboolean late_transit_on(void *data) g_source_remove(transit_timer); transit_timer = 0; - backlight_ops->transit_state(DPMS_ON); + display_backlight_change_brightness_by_dpms_state(DPMS_ON); return G_SOURCE_REMOVE; } @@ -643,7 +643,7 @@ inline void lcd_off_procedure(enum device_flags flag) } if (flags & LCD_PHASED_TRANSIT_MODE) - backlight_ops->transit_state(DPMS_OFF); + display_backlight_change_brightness_by_dpms_state(DPMS_OFF); SYS_G_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); diff --git a/plugins/wearable/display/display-handler.c b/plugins/wearable/display/display-handler.c index 47912b1..7fd9087 100644 --- a/plugins/wearable/display/display-handler.c +++ b/plugins/wearable/display/display-handler.c @@ -30,6 +30,7 @@ #include "shared/common.h" #include "shared/devices.h" #include "display/display-actor.h" +#include "display/display-backlight.h" #include "display/display-ops.h" #include "display-info.h" @@ -59,7 +60,7 @@ static gboolean lcdon_from_aod_cb(gpointer data) if (dpms_get_cached_state() != DPMS_ON) return G_SOURCE_REMOVE; - backlight_ops->transit_state(DPMS_ON); + display_backlight_change_brightness_by_dpms_state(DPMS_ON); display_info.set_brightness_level(level); /* lcdon is completed, aod disappered */ @@ -142,7 +143,7 @@ static void aod_change_signal(GDBusConnection *conn, if (!aod_clock_displayed) return; - backlight_ops->transit_state(DPMS_ON); + display_backlight_change_brightness_by_dpms_state(DPMS_ON); if (autobrt_timer) { /* if there is reserved level, apply it */ g_source_remove(autobrt_timer); autobrt_timer = 0; diff --git a/src/display/display-backlight.c b/src/display/display-backlight.c index 8579e36..a32a13c 100644 --- a/src/display/display-backlight.c +++ b/src/display/display-backlight.c @@ -241,6 +241,50 @@ void display_backlight_change_brightness(int start, int end, int step) } } +/* FIXME: display_backlight_get_brightness is duplicated, this code structure should be changed */ +/* It was operated only AOD enter & leave */ +int display_backlight_change_brightness_by_dpms_state(enum dpms_state state) +{ + int brt, val; + int start, end; + int default_brightness; + + display_backlight_get_default_brightness(&default_brightness); + + if (backlight_ops && backlight_ops->transit_state) + return backlight_ops->transit_state((int)state); + + display_backlight_get_brightness(&brt); + + if (state == DPMS_OFF) { + start = brt; + end = display_conf->aod_enter_level; + + /* + * The value of display_backlight_get_brightness is system brightness. + * But when device is LBM, the value is not same with real brightness. + * So it should be read exactly value for transit smooth effect + */ + display_backlight_get_brightness(&val); + + if (val > display_conf->aod_enter_level) + display_backlight_change_brightness(start, end, display_conf->brightness_change_step); + } else { + /* prevent transit effect when another effect is already executed */ + if (brt != display_conf->aod_enter_level) { + _W("effect is already executed brt(%d) aod_level(%d)", + brt, display_conf->aod_enter_level); + return 0; + } + + start = display_conf->aod_enter_level; + end = default_brightness; + display_backlight_change_brightness(start, end, display_conf->brightness_change_step); + } + + return 0; +} + int display_backlight_set_default_brightness(int brightness) { if (brightness < PM_MIN_BRIGHTNESS || brightness > PM_MAX_BRIGHTNESS) { diff --git a/src/display/display-backlight.h b/src/display/display-backlight.h index 538d7c7..8a5855c 100644 --- a/src/display/display-backlight.h +++ b/src/display/display-backlight.h @@ -19,6 +19,8 @@ #ifndef __DISPLAY_BACKLIGHT_H__ #define __DISPLAY_BACKLIGHT_H__ +#include "shared/devices.h" + int display_backlight_get_max_brightness(int *max_brightness); int display_backlight_get_normalized_brightness(int raw_brightness, int *normalized_brightness); @@ -26,6 +28,7 @@ int display_backlight_set_brightness(int brightness); int display_backlight_get_brightness(int *brightness); int display_backlight_get_brightness_by_plugin_profile(int *brightness); void display_backlight_change_brightness(int start, int end, int step); +int display_backlight_change_brightness_by_dpms_state(enum dpms_state state); int display_backlight_set_default_brightness(int brightness); int display_backlight_get_default_brightness(int *brightness); int display_backlight_update_by_default_brightness(void); -- 2.7.4