From 5163517997cc4566ceb390fd842b5f227ad3b4b3 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Thu, 16 Feb 2023 15:16:07 +0900 Subject: [PATCH] display: Move white_balance_ops functions from plugins to core display module Remove and redefine functions related to display white balance work. Because white balancing is common for display. Thus, these functions are added below display-panel. int display_panel_set_white_balance(enum hal_display_white_balance white_balance_type, int value) int display_panel_get_white_balance(enum hal_display_white_balance white_balance_type, int* out_val) -> With hal_display_white_balance enum type, it is possible to get and set white_balance values. Change-Id: I10213315d109e47f0e8c3a58382648ccef3ca2d1 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 5 -- plugins/iot-headed/display/device-interface.c | 87 ------------------------ plugins/mobile/display/core.c | 5 -- plugins/mobile/display/device-interface.c | 87 ------------------------ plugins/tv/display/core.c | 5 -- plugins/tv/display/device-interface.c | 87 ------------------------ plugins/wearable/display/core.c | 5 -- plugins/wearable/display/device-interface.c | 87 ------------------------ src/display/device-interface.h | 7 -- src/display/display-dbus.c | 10 +-- src/display/display-panel.c | 95 +++++++++++++++++++++++++++ src/display/display-panel.h | 27 ++++++++ 12 files changed, 125 insertions(+), 382 deletions(-) create mode 100644 src/display/display-panel.c create mode 100644 src/display/display-panel.h diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 8e2fd12..0a87e47 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -91,7 +91,6 @@ extern void init_save_userlock(void); static struct display_plugin *disp_plgn; static struct _backlight_ops *backlight_ops; -static struct _display_white_balance_ops *display_white_balance_ops; static struct battery_plugin *battery_plgn; static int (*fp_get_charging_status) (int *val); static void (*power_saving_func) (int onoff); @@ -2352,10 +2351,6 @@ static void __CONSTRUCTOR__ initialize(void) if (!backlight_ops) _E("Failed to get backlight operator variable."); - display_white_balance_ops = get_var_display_white_balance_ops(); - if (!display_white_balance_ops) - _E("Failed to get display white balance operator variable."); - battery_plgn = get_var_battery_plugin(); if (!battery_plgn) _E("Failed to get battery plugin variable."); diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index c6bf212..ecb5eb2 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -55,11 +55,6 @@ #define LCD_PHASED_DELAY 10000 /* microsecond */ #define DUMP_MODE_WAITING_TIME 600000 /* milisecond */ -#define MAX_WHITE_BALANCE_GAIN 2047 -#define MAX_WHITE_BALANCE_OFFSET 2047 -#define DEFAULT_WHITE_BALANCE_GAIN 1024 -#define DEFAULT_WHITE_BALANCE_OFFSET 0 - #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" #define GESTURE_STR "gesture" @@ -74,7 +69,6 @@ #define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" static struct _backlight_ops backlight_ops; -static struct _display_white_balance_ops display_white_balance_ops; static bool custom_status; static int custom_brightness; static int force_brightness; @@ -89,11 +83,6 @@ inline struct _backlight_ops *get_var_backlight_ops(void) return &backlight_ops; } -inline struct _display_white_balance_ops *get_var_display_white_balance_ops(void) -{ - return &display_white_balance_ops; -} - bool display_dev_ready(void) { return display_dev_available; @@ -750,77 +739,6 @@ static void release_blink(void) release_timer = g_timeout_add(DUMP_MODE_WAITING_TIME, release_blink_cb, NULL); } -static int set_white_balance(enum hal_display_white_balance white_balance_type, int value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - if (value > MAX_WHITE_BALANCE_GAIN) - value = DEFAULT_WHITE_BALANCE_GAIN; - break; - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - if (value > MAX_WHITE_BALANCE_OFFSET) - value = DEFAULT_WHITE_BALANCE_OFFSET; - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_set_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Set white balance is not supported."); - else - _E("Failed to set white balance value."); - } - - return ret; -} - -static int get_white_balance(enum hal_display_white_balance white_balance_type, int* value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_get_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Get white balance is not supported."); - else - _E("Failed to get white balance value."); - } - - return ret; -} - static void restore_brightness_func(void) { backlight_ops.set_brightness = set_brightness; @@ -859,11 +777,6 @@ static struct _backlight_ops backlight_ops = { .release_blink = release_blink, }; -static struct _display_white_balance_ops display_white_balance_ops = { - .set_white_balance = set_white_balance, - .get_white_balance = get_white_balance, -}; - int display_service_load(void) { int r; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 9078ff4..7948278 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -92,7 +92,6 @@ extern void init_save_userlock(void); static struct display_plugin *disp_plgn; static struct _backlight_ops *backlight_ops; -static struct _display_white_balance_ops *display_white_balance_ops; static struct battery_plugin *battery_plgn; static int (*fp_get_charging_status) (int *val); @@ -2363,10 +2362,6 @@ static void __CONSTRUCTOR__ initialize(void) if (!backlight_ops) _E("Failed to get backlight operator variable."); - display_white_balance_ops = get_var_display_white_balance_ops(); - if (!display_white_balance_ops) - _E("Failed to get display white balance operator variable."); - battery_plgn = get_var_battery_plugin(); if (!battery_plgn) _E("Failed to get battery plugin variable."); diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 14c5fd5..cef8002 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -56,11 +56,6 @@ #define LCD_PHASED_DELAY 10000 /* microsecond */ #define DUMP_MODE_WAITING_TIME 600000 /* milisecond */ -#define MAX_WHITE_BALANCE_GAIN 2047 -#define MAX_WHITE_BALANCE_OFFSET 2047 -#define DEFAULT_WHITE_BALANCE_GAIN 1024 -#define DEFAULT_WHITE_BALANCE_OFFSET 0 - #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" #define GESTURE_STR "gesture" @@ -73,7 +68,6 @@ #define UNKNOWN_STR "unknown" static struct _backlight_ops backlight_ops; -static struct _display_white_balance_ops display_white_balance_ops; static bool custom_status; static int custom_brightness; static int force_brightness; @@ -88,11 +82,6 @@ inline struct _backlight_ops *get_var_backlight_ops(void) return &backlight_ops; } -inline struct _display_white_balance_ops *get_var_display_white_balance_ops(void) -{ - return &display_white_balance_ops; -} - bool display_dev_ready(void) { return display_dev_available; @@ -749,77 +738,6 @@ static void release_blink(void) release_timer = g_timeout_add(DUMP_MODE_WAITING_TIME, release_blink_cb, NULL); } -static int set_white_balance(enum hal_display_white_balance white_balance_type, int value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - if (value > MAX_WHITE_BALANCE_GAIN) - value = DEFAULT_WHITE_BALANCE_GAIN; - break; - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - if (value > MAX_WHITE_BALANCE_OFFSET) - value = DEFAULT_WHITE_BALANCE_OFFSET; - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_set_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Set white balance is not supported."); - else - _E("Failed to set white balance value."); - } - - return ret; -} - -static int get_white_balance(enum hal_display_white_balance white_balance_type, int* value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_get_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Get white balance is not supported."); - else - _E("Failed to get white balance value."); - } - - return ret; -} - static void restore_brightness_func(void) { backlight_ops.set_brightness = set_brightness; @@ -858,11 +776,6 @@ static struct _backlight_ops backlight_ops = { .release_blink = release_blink, }; -static struct _display_white_balance_ops display_white_balance_ops = { - .set_white_balance = set_white_balance, - .get_white_balance = get_white_balance, -}; - int display_service_load(void) { int r; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 90f4e67..f9655cd 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -90,7 +90,6 @@ extern void init_save_userlock(void); static struct display_plugin *disp_plgn; static struct _backlight_ops *backlight_ops; -static struct _display_white_balance_ops *display_white_balance_ops; static struct battery_plugin *battery_plgn; static int (*fp_get_charging_status) (int *val); @@ -2349,10 +2348,6 @@ static void __CONSTRUCTOR__ initialize(void) if (!backlight_ops) _E("Failed to get backlight operator variable."); - display_white_balance_ops = get_var_display_white_balance_ops(); - if (!display_white_balance_ops) - _E("Failed to get display white balance operator variable."); - battery_plgn = get_var_battery_plugin(); if (!battery_plgn) _E("Failed to get battery plugin variable."); diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index ad11487..8c1cd1c 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -55,11 +55,6 @@ #define LCD_PHASED_DELAY 10000 /* microsecond */ #define DUMP_MODE_WAITING_TIME 600000 /* milisecond */ -#define MAX_WHITE_BALANCE_GAIN 2047 -#define MAX_WHITE_BALANCE_OFFSET 2047 -#define DEFAULT_WHITE_BALANCE_GAIN 1024 -#define DEFAULT_WHITE_BALANCE_OFFSET 0 - #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" #define GESTURE_STR "gesture" @@ -74,7 +69,6 @@ #define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" static struct _backlight_ops backlight_ops; -static struct _display_white_balance_ops display_white_balance_ops; static bool custom_status; static int custom_brightness; static int force_brightness; @@ -89,11 +83,6 @@ inline struct _backlight_ops *get_var_backlight_ops(void) return &backlight_ops; } -inline struct _display_white_balance_ops *get_var_display_white_balance_ops(void) -{ - return &display_white_balance_ops; -} - bool display_dev_ready(void) { return display_dev_available; @@ -750,77 +739,6 @@ static void release_blink(void) release_timer = g_timeout_add(DUMP_MODE_WAITING_TIME, release_blink_cb, NULL); } -static int set_white_balance(enum hal_display_white_balance white_balance_type, int value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - if (value > MAX_WHITE_BALANCE_GAIN) - value = DEFAULT_WHITE_BALANCE_GAIN; - break; - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - if (value > MAX_WHITE_BALANCE_OFFSET) - value = DEFAULT_WHITE_BALANCE_OFFSET; - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_set_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Set white balance is not supported."); - else - _E("Failed to set white balance value."); - } - - return ret; -} - -static int get_white_balance(enum hal_display_white_balance white_balance_type, int* value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_get_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Get white balance is not supported."); - else - _E("Failed to get white balance value."); - } - - return ret; -} - static void restore_brightness_func(void) { backlight_ops.set_brightness = set_brightness; @@ -859,11 +777,6 @@ static struct _backlight_ops backlight_ops = { .release_blink = release_blink, }; -static struct _display_white_balance_ops display_white_balance_ops = { - .set_white_balance = set_white_balance, - .get_white_balance = get_white_balance, -}; - int display_service_load(void) { int r; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 3947491..293206d 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -101,7 +101,6 @@ extern void init_save_userlock(void); static struct display_plugin *disp_plgn; static struct _backlight_ops *backlight_ops; -static struct _display_white_balance_ops *display_white_balance_ops; static struct battery_plugin *battery_plgn; static int (*fp_get_charging_status) (int *val); @@ -2680,10 +2679,6 @@ static void __CONSTRUCTOR__ initialize(void) if (!backlight_ops) _E("Failed to get backlight operator variable."); - display_white_balance_ops = get_var_display_white_balance_ops(); - if (!display_white_balance_ops) - _E("Failed to get display white balance operator variable."); - battery_plgn = get_var_battery_plugin(); if (!battery_plgn) _E("Failed to get battery plugin variable."); diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index d9fe84f..9689dd0 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -58,11 +58,6 @@ #define LCD_PHASED_DELAY 10000 /* microsecond */ #define DUMP_MODE_WAITING_TIME 600000 /* milisecond */ -#define MAX_WHITE_BALANCE_GAIN 2047 -#define MAX_WHITE_BALANCE_OFFSET 2047 -#define DEFAULT_WHITE_BALANCE_GAIN 1024 -#define DEFAULT_WHITE_BALANCE_OFFSET 0 - #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" #define GESTURE_STR "gesture" @@ -79,7 +74,6 @@ static struct _backlight_ops backlight_ops; -static struct _display_white_balance_ops display_white_balance_ops; static struct battery_plugin *battery_plgn; static bool custom_status; static int custom_brightness; @@ -101,11 +95,6 @@ inline struct _backlight_ops *get_var_backlight_ops(void) return &backlight_ops; } -inline struct _display_white_balance_ops *get_var_display_white_balance_ops(void) -{ - return &display_white_balance_ops; -} - bool display_dev_ready(void) { return display_dev_available; @@ -822,77 +811,6 @@ static void restore_brightness_func(void) backlight_ops.transit_brt = change_brightness; } -static int set_white_balance(enum hal_display_white_balance white_balance_type, int value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - if (value > MAX_WHITE_BALANCE_GAIN) - value = DEFAULT_WHITE_BALANCE_GAIN; - break; - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - if (value > MAX_WHITE_BALANCE_OFFSET) - value = DEFAULT_WHITE_BALANCE_OFFSET; - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_set_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Set white balance is not supported."); - else - _E("Failed to set white balance value."); - } - - return ret; -} - -static int get_white_balance(enum hal_display_white_balance white_balance_type, int* value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_get_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Get white balance is not supported."); - else - _E("Failed to get white balance value."); - } - - return ret; -} - static struct _backlight_ops backlight_ops = { .off = backlight_off, .dim = backlight_dim, @@ -926,11 +844,6 @@ static struct _backlight_ops backlight_ops = { .get_brightness_raw = get_brightness, /* always fetch brightness from node even LBM mode */ }; -static struct _display_white_balance_ops display_white_balance_ops = { - .set_white_balance = set_white_balance, - .get_white_balance = get_white_balance, -}; - int display_service_load(void) { int r; diff --git a/src/display/device-interface.h b/src/display/device-interface.h index 56b41e4..759ff50 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -94,13 +94,6 @@ struct _backlight_ops { struct _backlight_ops *get_var_backlight_ops(void); -struct _display_white_balance_ops { - int (*set_white_balance)(enum hal_display_white_balance white_balance_type, int value); - int (*get_white_balance)(enum hal_display_white_balance white_balance_type, int* out_val); -}; - -struct _display_white_balance_ops *get_var_display_white_balance_ops(void); - enum dpms_state { DPMS_ON, /* In use */ DPMS_STANDBY, /* Blanked, low power */ diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index c181d0f..5c92a43 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -44,6 +44,7 @@ #include "display.h" #include "shared/plugin.h" #include "display-lock.h" +#include "display-panel.h" #define AUL_APPSTATUS_PATH "/Org/Tizen/Aul/AppStatus" #define AUL_APPSTATUS_INTERFACE "org.tizen.aul.AppStatus" @@ -72,7 +73,6 @@ static struct display_plugin *disp_plgn; static struct _backlight_ops *backlight_ops; -static struct _display_white_balance_ops *display_white_balance_ops; static struct display_config *display_conf; static GVariant *dbus_start(GDBusConnection *conn, @@ -1210,7 +1210,7 @@ static GVariant *dbus_setwhitebalance(GDBusConnection *conn, g_variant_get(param, "(ii)", &white_balance_type, &value); - ret_val = display_white_balance_ops->set_white_balance(white_balance_type, value); + ret_val = display_panel_set_white_balance(white_balance_type, value); if (ret_val < 0) { _E("Failed to set white balance"); ret = -EPERM; @@ -1232,7 +1232,7 @@ static GVariant *dbus_getwhitebalance(GDBusConnection *conn, g_variant_get(param, "(i)", &white_balance_type); - ret = display_white_balance_ops->get_white_balance(white_balance_type, &ret_val); + ret = display_panel_get_white_balance(white_balance_type, &ret_val); if (ret < 0) { _E("Failed to get white balance"); ret = -EPERM; @@ -1474,10 +1474,6 @@ static void __CONSTRUCTOR__ initialize(void) if (!backlight_ops) _E("Failed to get backlight operator variable."); - display_white_balance_ops = get_var_display_white_balance_ops(); - if (!display_white_balance_ops) - _E("Failed to get display white balance operator variable."); - display_conf = get_var_display_config(); if (!display_conf) _E("Failed to get display configuration variable."); diff --git a/src/display/display-panel.c b/src/display/display-panel.c new file mode 100644 index 0000000..9d65416 --- /dev/null +++ b/src/display/display-panel.c @@ -0,0 +1,95 @@ +/* + * deviced + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "shared/log.h" +#include "display-panel.h" +#include "display.h" + +#define MAX_WHITE_BALANCE_GAIN 2047 +#define MAX_WHITE_BALANCE_OFFSET 2047 +#define DEFAULT_WHITE_BALANCE_GAIN 1024 +#define DEFAULT_WHITE_BALANCE_OFFSET 0 + +int display_panel_set_white_balance(enum hal_display_white_balance white_balance_type, + int value) +{ + int ret = 0; + + if (!display_is_hal_backend_available()) { + _E("There is no display device."); + return -ENOENT; + } + + switch (white_balance_type) { + case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: + case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: + case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: + if (value > MAX_WHITE_BALANCE_GAIN) + value = DEFAULT_WHITE_BALANCE_GAIN; + break; + case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: + case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: + case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: + if (value > MAX_WHITE_BALANCE_OFFSET) + value = DEFAULT_WHITE_BALANCE_OFFSET; + break; + default: + _E("Unknown white balance type"); + return -EINVAL; + } + + ret = hal_device_display_set_white_balance(white_balance_type, value); + if (ret == -ENODEV) + _E("Set white balance is not supported."); + else if (ret < 0) + _E("Failed to set white balance value."); + + return ret; +} + +int display_panel_get_white_balance(enum hal_display_white_balance white_balance_type, + int* value) +{ + int ret = 0; + + if (!display_is_hal_backend_available()) { + _E("There is no display device."); + return -ENOENT; + } + + switch (white_balance_type) { + case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: + case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: + case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: + case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: + case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: + case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: + break; + default: + _E("Unknown white balance type"); + return -EINVAL; + } + + ret = hal_device_display_get_white_balance(white_balance_type, value); + if (ret == -ENODEV) + _E("Get white balance is not supported."); + else if (ret < 0) + _E("Failed to get white balance value."); + + return ret; +} \ No newline at end of file diff --git a/src/display/display-panel.h b/src/display/display-panel.h new file mode 100644 index 0000000..efe6e45 --- /dev/null +++ b/src/display/display-panel.h @@ -0,0 +1,27 @@ +/* + * deviced + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __DISPLAY_PANEL_H__ +#define __DISPLAY_PANEL_H__ + +#include + +int display_panel_set_white_balance(enum hal_display_white_balance white_balance_type, int value); +int display_panel_get_white_balance(enum hal_display_white_balance white_balance_type, int* out_val); + +#endif /* __DISPLAY_PANEL_H__ */ \ No newline at end of file -- 2.7.4