From 3d4ba919a2ca61f36a35af168abfcc28d830d13c Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Wed, 22 Feb 2023 14:20:53 +0900 Subject: [PATCH] display: Move default_brightness getter and setter from plugin to core display module Remove and redefine default brightness getter/setter. These functions are added below display-backlight. int display_backlight_set_default_brightness(int brightness) int display_backlight_get_default_brightness(int *brightness) -> With these functions, it is possible to get and set default brightness value. Change-Id: Iaa851094abf051f2fe15c64ff8e94376cc2b6382 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 5 ++-- plugins/iot-headed/display/device-interface.c | 29 +++++++----------- plugins/mobile/display/core.c | 5 ++-- plugins/mobile/display/device-interface.c | 29 +++++++----------- plugins/tv/display/core.c | 5 ++-- plugins/tv/display/device-interface.c | 29 +++++++----------- .../wearable/display/auto-brightness-sensorhub.c | 11 +++---- plugins/wearable/display/core.c | 5 ++-- plugins/wearable/display/device-interface.c | 29 +++++++----------- src/display/auto-brightness.c | 5 ++-- src/display/device-interface.h | 2 -- src/display/display-backlight.c | 34 ++++++++++++++++++++++ src/display/display-backlight.h | 2 ++ src/display/display-dbus.c | 7 +++-- 14 files changed, 101 insertions(+), 96 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index f8ecf49..e894b2a 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -63,6 +63,7 @@ #include "display-dpms.h" #include "display-signal.h" #include "display-lock.h" +#include "display-backlight.h" #include "shared/plugin.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -1632,7 +1633,7 @@ static int update_setting(int key_idx, int val) _I("Brightness changed in low battery," "escape dim state."); } - backlight_ops->set_default_brt(val); + display_backlight_set_default_brightness(val); break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); @@ -1695,7 +1696,7 @@ static void check_seed_status(void) tmp = brt; } _I("Set brightness(%d) from setting app.", tmp); - backlight_ops->set_default_brt(tmp); + display_backlight_set_default_brightness(tmp); backlight_ops->set_brightness(tmp); ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index a719e4f..777b27f 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -74,7 +74,6 @@ static struct _backlight_ops backlight_ops; static bool custom_status; static int custom_brightness; static int force_brightness; -static int default_brightness; static int dpms_running_state = DPMS_SETTING_DONE; static bool display_dev_available = false; static guint release_timer; @@ -224,6 +223,9 @@ static int backlight_off(enum device_flags flags) { int ret = -1; static int cnt, ambient_cnt; + int default_brightness = 0; + + display_backlight_get_default_brightness(&default_brightness); if (flags & AMBIENT_MODE) { _I("[DPMS XLIB Backlight] LCD suspend %#x cnt:%d", flags, ambient_cnt); @@ -327,7 +329,7 @@ static int backlight_update(void) if (display_dimstay_check()) ret = backlight_dim(); else { - brt = backlight_ops.get_default_brt(); + display_backlight_get_default_brightness(&brt); ret = backlight_ops.set_brightness(brt); } return ret; @@ -345,24 +347,12 @@ static int backlight_standby(int force) return ret; } -static int set_default_brt(int level) -{ - if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS) - level = display_conf->pm_default_brightness; - - default_brightness = level; - - return 0; -} - -static int get_default_brt(void) -{ - return default_brightness; -} - static int set_brightness(int val) { int max, ret; + int default_brightness = 0; + + display_backlight_get_default_brightness(&default_brightness); if (!display_dev_available) { _E("There is no display device."); @@ -454,6 +444,9 @@ static int backlight_transit_state(int state) { int brt, val; int start, end; + int default_brightness = 0; + + display_backlight_get_default_brightness(&default_brightness); backlight_ops.get_brightness(&brt); @@ -550,8 +543,6 @@ static struct _backlight_ops backlight_ops = { .on = backlight_on, .update = backlight_update, .standby = backlight_standby, - .set_default_brt = set_default_brt, - .get_default_brt = get_default_brt, .get_lcd_power = dpms_get_cached_state, .get_lcd_power_node = get_lcd_power_node, .set_custom_status = set_custom_status, diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 6980389..007ecec 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -64,6 +64,7 @@ #include "display-info.h" #include "display-signal.h" #include "display-lock.h" +#include "display-backlight.h" #include "shared/plugin.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -1642,7 +1643,7 @@ static int update_setting(int key_idx, int val) _I("Brightness changed in low battery," "escape dim state."); } - backlight_ops->set_default_brt(val); + display_backlight_set_default_brightness(val); break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); @@ -1705,7 +1706,7 @@ static void check_seed_status(void) tmp = brt; } _I("Set brightness(%d) from setting app.", tmp); - backlight_ops->set_default_brt(tmp); + display_backlight_set_default_brightness(tmp); backlight_ops->set_brightness(tmp); ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index fe0fd8b..eb4dc95 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -73,7 +73,6 @@ static struct _backlight_ops backlight_ops; static bool custom_status; static int custom_brightness; static int force_brightness; -static int default_brightness; static int dpms_running_state = DPMS_SETTING_DONE; static bool display_dev_available = false; static guint release_timer; @@ -223,6 +222,9 @@ static int backlight_off(enum device_flags flags) { int ret = -1; static int cnt, ambient_cnt; + int default_brightness = 0; + + display_backlight_get_default_brightness(&default_brightness); if (flags & AMBIENT_MODE) { _I("[DPMS XLIB Backlight] LCD suspend %#x cnt:%d", flags, ambient_cnt); @@ -326,7 +328,7 @@ static int backlight_update(void) if (display_dimstay_check()) ret = backlight_dim(); else { - brt = backlight_ops.get_default_brt(); + display_backlight_get_default_brightness(&brt); ret = backlight_ops.set_brightness(brt); } return ret; @@ -344,24 +346,12 @@ static int backlight_standby(int force) return ret; } -static int set_default_brt(int level) -{ - if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS) - level = display_conf->pm_default_brightness; - - default_brightness = level; - - return 0; -} - -static int get_default_brt(void) -{ - return default_brightness; -} - static int set_brightness(int val) { int max, ret; + int default_brightness = 0; + + display_backlight_get_default_brightness(&default_brightness); if (!display_dev_available) { _E("There is no display device."); @@ -453,6 +443,9 @@ static int backlight_transit_state(int state) { int brt, val; int start, end; + int default_brightness = 0; + + display_backlight_get_default_brightness(&default_brightness); backlight_ops.get_brightness(&brt); @@ -549,8 +542,6 @@ static struct _backlight_ops backlight_ops = { .on = backlight_on, .update = backlight_update, .standby = backlight_standby, - .set_default_brt = set_default_brt, - .get_default_brt = get_default_brt, .get_lcd_power = dpms_get_cached_state, .get_lcd_power_node = get_lcd_power_node, .set_custom_status = set_custom_status, diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index b1e1ab7..99393dd 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -62,6 +62,7 @@ #include "display-dpms.h" #include "display-signal.h" #include "display-lock.h" +#include "display-backlight.h" #include "shared/plugin.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -1632,7 +1633,7 @@ static int update_setting(int key_idx, int val) _I("Brightness changed in low battery," "escape dim state."); } - backlight_ops->set_default_brt(val); + display_backlight_set_default_brightness(val); break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); @@ -1695,7 +1696,7 @@ static void check_seed_status(void) tmp = brt; } _I("Set brightness(%d) from setting app.", tmp); - backlight_ops->set_default_brt(tmp); + display_backlight_set_default_brightness(tmp); backlight_ops->set_brightness(tmp); ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index d5caa72..768575b 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -74,7 +74,6 @@ static struct _backlight_ops backlight_ops; static bool custom_status; static int custom_brightness; static int force_brightness; -static int default_brightness; static int dpms_running_state = DPMS_SETTING_DONE; static bool display_dev_available = false; static guint release_timer; @@ -224,6 +223,9 @@ static int backlight_off(enum device_flags flags) { int ret = -1; static int cnt, ambient_cnt; + int default_brightness = 0; + + display_backlight_get_default_brightness(&default_brightness); if (flags & AMBIENT_MODE) { _I("[DPMS XLIB Backlight] LCD suspend %#x cnt:%d", flags, ambient_cnt); @@ -327,7 +329,7 @@ static int backlight_update(void) if (display_dimstay_check()) ret = backlight_dim(); else { - brt = backlight_ops.get_default_brt(); + display_backlight_get_default_brightness(&brt); ret = backlight_ops.set_brightness(brt); } return ret; @@ -345,24 +347,12 @@ static int backlight_standby(int force) return ret; } -static int set_default_brt(int level) -{ - if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS) - level = display_conf->pm_default_brightness; - - default_brightness = level; - - return 0; -} - -static int get_default_brt(void) -{ - return default_brightness; -} - static int set_brightness(int val) { int max, ret; + int default_brightness = 0; + + display_backlight_get_default_brightness(&default_brightness); if (!display_dev_available) { _E("There is no display device."); @@ -454,6 +444,9 @@ static int backlight_transit_state(int state) { int brt, val; int start, end; + int default_brightness = 0; + + display_backlight_get_default_brightness(&default_brightness); backlight_ops.get_brightness(&brt); @@ -550,8 +543,6 @@ static struct _backlight_ops backlight_ops = { .on = backlight_on, .update = backlight_update, .standby = backlight_standby, - .set_default_brt = set_default_brt, - .get_default_brt = get_default_brt, .get_lcd_power = dpms_get_cached_state, .get_lcd_power_node = get_lcd_power_node, .set_custom_status = set_custom_status, diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c index 51950bf..451072b 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.c +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -30,6 +30,7 @@ #include "display/util.h" #include "display/core.h" #include "display/display-ops.h" +#include "display/display-backlight.h" #include "shared/device-notifier.h" #include "battery/power-supply.h" #include "shared/plugin.h" @@ -92,7 +93,7 @@ static void set_brightness_level(int level) auto_brightness_control(BR_HBM_ON, BR_IMPLICIT); break; case SPECIFIC_MODE_OFF: - default_brightness = backlight_ops->get_default_brt(); + display_backlight_get_default_brightness(&default_brightness); backlight_ops->get_brightness(¤t_brightness); /* Disable HBM, LBM */ @@ -124,8 +125,8 @@ static void set_default_brightness(void) { int default_brt; - default_brt = backlight_ops->get_default_brt(); - backlight_ops->set_default_brt(default_brt); + display_backlight_get_default_brightness(&default_brt); + display_backlight_set_default_brightness(default_brt); backlight_ops->update(); } @@ -185,7 +186,7 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes int current_brightness; int ret; - default_brightness = backlight_ops->get_default_brt(); + display_backlight_get_default_brightness(&default_brightness); backlight_ops->get_brightness(¤t_brightness); if (request == BR_LBM_ON) { @@ -296,7 +297,7 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes lbm_set_state(true); change_flag(&lowdim, 0); change_flag(&hold_brt, 0); - backlight_ops->set_default_brt(set_brightness); + display_backlight_set_default_brightness(set_brightness); if (!hbm) { ret = backlight_ops->set_brightness(set_brightness); if (ret < 0) { diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index da8f29e..8fa7d4f 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -65,6 +65,7 @@ #include "battery-monitor.h" #include "display/display-signal.h" #include "display-lock.h" +#include "display-backlight.h" #include "shared/plugin.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -1903,7 +1904,7 @@ static int update_setting(int key_idx, int val) _I("Brightness changed in low battery," "escape dim state."); } - backlight_ops->set_default_brt(val); + display_backlight_set_default_brightness(val); break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); @@ -1962,7 +1963,7 @@ static void check_seed_status(void) tmp = brt; } _I("Set brightness(%d) from setting app.", tmp); - backlight_ops->set_default_brt(tmp); + display_backlight_set_default_brightness(tmp); backlight_ops->set_brightness(tmp); ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 72cf022..779d8c6 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -80,7 +80,6 @@ static struct battery_plugin *battery_plgn; static bool custom_status; static int custom_brightness; static int force_brightness; -static int default_brightness; static int dpms_running_state = DPMS_SETTING_DONE; static bool display_dev_available = false; static guint release_timer; @@ -235,6 +234,9 @@ static int backlight_off(enum device_flags flags) { int ret = -1; static int cnt, ambient_cnt; + int default_brightness = 0; + + display_backlight_get_default_brightness(&default_brightness); if (flags & AMBIENT_MODE) { _I("[DPMS XLIB Backlight] LCD suspend %#x cnt:%d", flags, ambient_cnt); @@ -338,7 +340,7 @@ static int backlight_update(void) if (display_dimstay_check()) ret = backlight_dim(); else { - brt = backlight_ops.get_default_brt(); + display_backlight_get_default_brightness(&brt); ret = backlight_ops.set_brightness(brt); } return ret; @@ -356,24 +358,12 @@ static int backlight_standby(int force) return ret; } -static int set_default_brt(int level) -{ - if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS) - level = display_conf->pm_default_brightness; - - default_brightness = level; - - return 0; -} - -static int get_default_brt(void) -{ - return default_brightness; -} - static int set_brightness(int val) { int max, ret; + int default_brightness = 0; + + display_backlight_get_default_brightness(&default_brightness); if (!display_dev_available) { _E("There is no display device."); @@ -467,6 +457,9 @@ static int backlight_transit_state(int state) int brt, val; int start, end; static int aod_brightness_level; + int default_brightness = 0; + + display_backlight_get_default_brightness(&default_brightness); backlight_ops.get_brightness(&brt); @@ -615,8 +608,6 @@ static struct _backlight_ops backlight_ops = { .on = backlight_on, .update = backlight_update, .standby = backlight_standby, - .set_default_brt = set_default_brt, - .get_default_brt = get_default_brt, .get_lcd_power = dpms_get_cached_state, .get_lcd_power_node = get_lcd_power_node, .set_custom_status = set_custom_status, diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index d7a740d..6c9e96a 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -32,6 +32,7 @@ #include "util.h" #include "core.h" #include "display-ops.h" +#include "display-backlight.h" #include "setting.h" #include "shared/device-notifier.h" #include @@ -146,7 +147,7 @@ static void alc_set_brightness(int setting, int value, float light) (step < 0 && tmp_value < value)) tmp_value = value; - backlight_ops->set_default_brt(tmp_value); + display_backlight_set_default_brightness(tmp_value); backlight_ops->update(); } _I("Load light data(%f) auto brt=%d min brightness=%d " @@ -442,7 +443,7 @@ static int set_autobrightness_state(int status) default_brt = brt; } - backlight_ops->set_default_brt(default_brt); + display_backlight_set_default_brightness(default_brt); backlight_ops->update(); } diff --git a/src/display/device-interface.h b/src/display/device-interface.h index c98b8b2..7461394 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -66,8 +66,6 @@ struct _backlight_ops { int (*on)(enum device_flags); int (*update)(void); int (*standby)(int); - int (*set_default_brt)(int level); - int (*get_default_brt)(void); int (*get_lcd_power)(void); int (*get_lcd_power_node)(void); int (*set_custom_status)(bool on); diff --git a/src/display/display-backlight.c b/src/display/display-backlight.c index eea7666..d6f78fb 100644 --- a/src/display/display-backlight.c +++ b/src/display/display-backlight.c @@ -19,8 +19,15 @@ #include #include "shared/log.h" +#include "power/power-suspend.h" +#include "core.h" #include "display.h" #include "display-backlight.h" +#include "display-dpms.h" + +static const struct display_config *display_conf; + +static int default_brightness; /* FIXME: This function is for temporary use, should be fixed after plugin refactoring */ int display_backlight_get_max_brightness(int *max_brightness) @@ -87,4 +94,31 @@ int display_backlight_get_normalized_brightness(int raw_brightness, *normalized_brightness = quotient; return 0; +} + +int display_backlight_set_default_brightness(int brightness) +{ + if (brightness < PM_MIN_BRIGHTNESS || brightness > PM_MAX_BRIGHTNESS) { + if (display_conf) + brightness = display_conf->pm_default_brightness; + else + return -EPERM; + } + + default_brightness = brightness; + return 0; +} + +/* FIXME: default_brightness value should be initialized by vconf_get_int */ +int display_backlight_get_default_brightness(int *brightness) +{ + *brightness = default_brightness; + return 0; +} + +static void __CONSTRUCTOR__ initialize(void) +{ + display_conf = get_var_display_config(); + if (!display_conf) + _W("Failed to get display configuration variable."); } \ No newline at end of file diff --git a/src/display/display-backlight.h b/src/display/display-backlight.h index cbf663c..afe21ff 100644 --- a/src/display/display-backlight.h +++ b/src/display/display-backlight.h @@ -22,5 +22,7 @@ int display_backlight_get_max_brightness(int *max_brightness); int display_backlight_get_normalized_brightness(int raw_brightness, int *normalized_brightness); +int display_backlight_set_default_brightness(int brightness); +int display_backlight_get_default_brightness(int *brightness); #endif /* __DISPLAY_BACKLIGHT_H__ */ \ No newline at end of file diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 7d31655..468c890 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -45,6 +45,7 @@ #include "shared/plugin.h" #include "display-lock.h" #include "display-panel.h" +#include "display-backlight.h" #define AUL_APPSTATUS_PATH "/Org/Tizen/Aul/AppStatus" #define AUL_APPSTATUS_INTERFACE "org.tizen.aul.AppStatus" @@ -423,7 +424,7 @@ static GVariant *dbus_getbrightness(GDBusConnection *conn, result = brt; } } else { - result = backlight_ops->get_default_brt(); + display_backlight_get_default_brightness(&result); brt = 0; } @@ -473,7 +474,7 @@ static GVariant *dbus_setbrightness(GDBusConnection *conn, if (disp_plgn->auto_brightness_control) { ret = disp_plgn->auto_brightness_control(BR_SET_BRIGHTNESS, brt); } else { - backlight_ops->set_default_brt(brt); + display_backlight_set_default_brightness(brt); ret = backlight_ops->set_brightness(brt); if (ret < 0) goto error; @@ -1194,7 +1195,7 @@ static GVariant *dbus_getbrightnessinfo(GDBusConnection *conn, int default_brightness; int current_brightness; - default_brightness = backlight_ops->get_default_brt(); + display_backlight_get_default_brightness(&default_brightness); backlight_ops->get_brightness_raw(¤t_brightness); return g_variant_new("(ii)", default_brightness, current_brightness); -- 2.7.4