Add image effect for display 66/202866/5 accepted/tizen/unified/20190410.002230 submit/tizen/20190409.053926
authorlokilee73 <changjoo.lee@samsung.com>
Fri, 5 Apr 2019 08:22:17 +0000 (17:22 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Tue, 9 Apr 2019 05:17:52 +0000 (14:17 +0900)
Change-Id: I9de4dec681193b93b18e5d98289dd5ab35a25837
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
plugins/wearable/display/device-interface.c
plugins/wearable/display/enhance.c [new file with mode: 0644]
src/core/device-notifier.h
src/display/device-interface.h

index a9088ac..745cb21 100755 (executable)
@@ -559,6 +559,45 @@ static int get_brightness_by_light_sensor(float lmax, float lmin, float light, i
        return 0;
 }
 
+static int get_image_effect(enum display_image_effect *effect)
+{
+       int ret;
+       enum display_image_effect val;
+
+       if (!display_dev || !display_dev->get_image_effect) {
+               _E("There is no display device");
+               return -ENOENT;
+       }
+
+       ret = display_dev->get_image_effect(&val);
+       if (ret < 0) {
+               _E("Failed to get image effect: %d", ret);
+               return ret;
+       }
+
+       *effect = val;
+
+       return 0;
+}
+
+static int set_image_effect(enum display_image_effect effect)
+{
+       int ret;
+
+       if (!display_dev || !display_dev->set_image_effect) {
+               _E("There is no display device");
+               return -ENOENT;
+       }
+
+       ret = display_dev->set_image_effect(effect);
+       if (ret < 0) {
+               _E("Failed to set image effect: %d", ret);
+               return ret;
+       }
+
+       return 0;
+}
+
 static int get_frame_rate(int *rate)
 {
        if (!rate)
@@ -627,6 +666,8 @@ static void _init_ops(void)
        backlight_ops.set_brightness = set_brightness;
        backlight_ops.get_brightness = get_brightness;
        backlight_ops.get_brightness_by_light_sensor = get_brightness_by_light_sensor;
+       backlight_ops.get_image_effect = get_image_effect;
+       backlight_ops.set_image_effect = set_image_effect;
        backlight_ops.get_frame_rate = get_frame_rate;
        backlight_ops.set_frame_rate = set_frame_rate;
 
diff --git a/plugins/wearable/display/enhance.c b/plugins/wearable/display/enhance.c
new file mode 100644 (file)
index 0000000..5d26c2e
--- /dev/null
@@ -0,0 +1,182 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2019 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 <stdio.h>
+#include <stdbool.h>
+#include <device-node.h>
+#include <vconf.h>
+#include <hw/display.h>
+#include <libgdbus/dbus-system.h>
+
+#include "display/core.h"
+#include "display/display-ops.h"
+#include "core/devices.h"
+#include "core/log.h"
+#include "core/common.h"
+#include "core/device-notifier.h"
+
+#define VCONF_HIGH_CONTRAST            VCONFKEY_SETAPPL_ACCESSIBILITY_HIGH_CONTRAST
+#define VCONF_GREYSCALE                        VCONFKEY_SETAPPL_ACCESSIBILITY_GREYSCALE
+
+static bool negative_status;
+static bool greyscale_status;
+
+static int enhance_update_state(void)
+{
+       int state;
+
+       _I("Greyscale %d negative %d", greyscale_status, negative_status);
+
+       if (greyscale_status) {
+               if (negative_status)
+                       state = DISPLAY_IMAGE_EFFECT_GREY_NEGATIVE;
+               else
+                       state = DISPLAY_IMAGE_EFFECT_GREY;
+       } else if (negative_status)
+               state = DISPLAY_IMAGE_EFFECT_NEGATIVE;
+       else
+               state = DISPLAY_IMAGE_EFFECT_STANDARD;
+
+       backlight_ops.set_image_effect(state);
+
+       return state;
+}
+
+static void enhance_greyscale_cb(keynode_t *in_key, void *data)
+{
+       int val, ret;
+
+       ret = vconf_get_bool(VCONF_GREYSCALE, &val);
+       if (ret < 0) {
+               _E("Failed to get %s", VCONF_GREYSCALE);
+               return;
+       }
+
+       _I("Set greyscale scenario (%d)", val);
+       greyscale_status = val;
+
+       enhance_update_state();
+}
+
+static void enhance_high_contrast_cb(keynode_t *in_key, void *data)
+{
+       int val, ret;
+
+       ret = vconf_get_bool(VCONF_HIGH_CONTRAST, &val);
+       if (ret < 0) {
+               _E("Failed to get %s", VCONF_HIGH_CONTRAST);
+               return;
+       }
+
+       _I("Set negative scenario (%d)", val);
+       negative_status = val;
+
+       enhance_update_state();
+}
+
+static int enhance_lcd_state_changed(void *data)
+{
+       int state;
+
+       state = DATA_VALUE_INT(data);
+
+       if (state == S_NORMAL)
+               enhance_update_state();
+
+       return 0;
+}
+
+static int enhance_ultrapowersaving_changed(void *data)
+{
+       bool mode;
+
+       mode = DATA_VALUE_BOOL(data);
+
+       greyscale_status = mode;
+
+       enhance_update_state();
+       _I("Set ultra power saving mode.");
+
+       return 0;
+
+}
+
+static void enhance_init(void *data)
+{
+       int val, ret;
+       int state;
+
+       /* register notifier */
+       register_notifier(DEVICE_NOTIFIER_LCD, enhance_lcd_state_changed);
+       register_notifier(DEVICE_NOTIFIER_ULTRAPOWERSAVING,
+           enhance_ultrapowersaving_changed);
+
+       ret = vconf_notify_key_changed(VCONF_HIGH_CONTRAST,
+           enhance_high_contrast_cb, NULL);
+       if (ret < 0)
+               _E("Failed to register notify: %s", VCONF_HIGH_CONTRAST);
+
+       ret = vconf_get_bool(VCONF_HIGH_CONTRAST, &val);
+       if (ret < 0)
+               _E("Failed to get high contrast!");
+
+       /* update negative status */
+       _I("Set high contrast (%d)", val);
+       negative_status = val;
+
+       ret = vconf_notify_key_changed(VCONF_GREYSCALE,
+           enhance_greyscale_cb, NULL);
+       if (ret < 0)
+               _E("Failed to register notify: %s", VCONF_GREYSCALE);
+
+       ret = vconf_get_bool(VCONF_GREYSCALE, &val);
+       if (ret < 0) {
+               _E("Failed to get high contrast!");
+               return;
+       }
+       greyscale_status = val;
+
+       state = enhance_update_state();
+
+       ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY,
+                                       DEVICED_INTERFACE_DISPLAY,
+                                       "Enhance",
+                                       g_variant_new("(i)", state));
+       if (ret < 0)
+               _E("Failed to send dbus signal.");
+}
+
+static void enhance_exit(void *data)
+{
+       /* unregister notifier */
+       unregister_notifier(DEVICE_NOTIFIER_LCD, enhance_lcd_state_changed);
+       unregister_notifier(DEVICE_NOTIFIER_ULTRAPOWERSAVING,
+           enhance_ultrapowersaving_changed);
+
+       vconf_ignore_key_changed(VCONF_HIGH_CONTRAST, enhance_high_contrast_cb);
+       vconf_ignore_key_changed(VCONF_GREYSCALE, enhance_greyscale_cb);
+}
+
+static const struct display_ops display_enhance_ops = {
+       .name     = "enhance",
+       .init     = enhance_init,
+       .exit     = enhance_exit,
+};
+
+DISPLAY_OPS_REGISTER(&display_enhance_ops)
index 6acc7d8..3196468 100644 (file)
@@ -71,6 +71,7 @@ enum device_notifier_type {
        DEVICE_NOTIFIER_UDEV,
        DEVICE_NOTIFIER_BEZEL_WAKEUP,
        DEVICE_NOTIFIER_LONGKEY_RESTORE,
+       DEVICE_NOTIFIER_ULTRAPOWERSAVING,
        DEVICE_NOTIFIER_MAX,
 };
 
index 7f2be5c..b277c2d 100644 (file)
@@ -25,6 +25,7 @@
 #define __DEVICE_INTERFACE_H__
 
 #include <stdbool.h>
+#include <hw/display.h>
 #include "core/devices.h"
 
 #define DEFAULT_DISPLAY 0
@@ -71,6 +72,8 @@ struct _backlight_ops {
        int (*set_brightness)(int val);
        int (*get_brightness)(int *val);
        int (*get_brightness_by_light_sensor)(float lmax, float lmin, float light, int *brt);
+       int (*get_image_effect)(enum display_image_effect *effect);
+       int (*set_image_effect)(enum display_image_effect effect);
        int (*get_frame_rate)(int *rate);
        int (*set_frame_rate)(int rate);
 };