From: Doyoun Kang Date: Fri, 8 Apr 2016 02:08:32 +0000 (+0900) Subject: Added new APIs for setting/getting brightness of screen X-Git-Tag: accepted/tizen/common/20160419.142946~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=141da17ec9ba983f7cb8da108651ffa621091dc9;p=platform%2Fcore%2Fapi%2Fefl-util.git Added new APIs for setting/getting brightness of screen Change-Id: I65a97922484db61058822c4a688b2e2c79d115f4 --- diff --git a/include/efl_util.h b/include/efl_util.h index 7ee6fca..4fb2363 100644 --- a/include/efl_util.h +++ b/include/efl_util.h @@ -257,6 +257,42 @@ API int efl_util_set_window_screen_mode_error_cb(Evas_Object *window, efl_util_w API int efl_util_unset_window_screen_mode_error_cb(Evas_Object *window); /** + * @brief Sets the user's preferred brightness of the specified window. + * @details This API is useful when the application need to change the brightness of the screen when it is appeared on the screen. + * If the application sets the brightness 0 to 100 to its window and the application window is shown wholly or partially, + * the window manager requests the display system to change the brightness of the screen using user's preferred brightness. + * If the window is no longer shown, then the window manger request the display system to go back to default brightness. + * If the brightness is less than 0, this means to use the default screen brightness. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * @remarks This API needs the privilege. + * If the application which is not get the privilege use this API, the window manager generates the permission deny error. + * @param[in] window The EFL window + * @param[in] brightness The preferred brightness + * @return @c 0 on success, otherwise a negative error value + * @retval #EFL_UTIL_ERROR_NONE Successful + * @retval #EFL_UTIL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #EFL_UTIL_ERROR_PERMISSION_DENIED Permission denied + * @retval #EFL_UTIL_ERROR_OUT_OF_MEMORY Out of memory + * @see efl_util_get_window_brightness() + */ +API int efl_util_set_window_brightness(Evas_Object *window, int brightness); + +/** + * @brief Gets the user's preferred brightness of the specified window. + * @since_tizen 3.0 + * @param[in] window The EFL window + * @param[out] brightness The preferred brightness + * @return @c 0 on success, otherwise a negative error value + * @retval #EFL_UTIL_ERROR_NONE Successful + * @retval #EFL_UTIL_ERROR_INVALID_PARAMETER Invalid parameter + * @see efl_util_set_window_brightness() + */ +API int efl_util_get_window_brightness(Evas_Object *window, int *brightness); + + +/** * @} */ diff --git a/src/efl_util.c b/src/efl_util.c index ad213a2..8bce9b9 100644 --- a/src/efl_util.c +++ b/src/efl_util.c @@ -80,6 +80,14 @@ typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info uint32_t state; } Efl_Util_Wl_Surface_Scr_Mode_Info; +typedef struct _Efl_Util_Wl_Surface_Brightness_Info +{ + void *surface; /* wl_surface */ + int brightness; + Eina_Bool wait_for_done; + uint32_t state; +} Efl_Util_Wl_Surface_Brightness_Info; + typedef struct _Efl_Util_Wl_Output_Info { struct wl_output *output; @@ -124,6 +132,11 @@ typedef struct _Efl_Util_Data struct tizen_input_device_manager *devicemgr; int request_notified; } devmgr; + struct + { + struct tizen_display_policy *proto; + Eina_Hash *hash_brightness; + } display_policy; } wl; #endif /* end of WAYLAND */ @@ -181,6 +194,8 @@ static void _cb_wl_tz_policy_iconify_state_changed(void *data static void _cb_wl_tz_policy_supported_aux_hints(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, struct wl_array *hints, uint32_t num_hints); static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id); +static void _cb_wl_tz_display_policy_brightness_done(void *data, struct tizen_display_policy *tizen_display_policy, struct wl_surface *surface_resource, int32_t brightness, uint32_t state); + static void _cb_device_add(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, const char *identifier EINA_UNUSED, struct tizen_input_device *device EINA_UNUSED, struct wl_seat *seat EINA_UNUSED); static void _cb_device_remove(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, const char *identifier EINA_UNUSED, struct tizen_input_device *device EINA_UNUSED, struct wl_seat *seat EINA_UNUSED); static void _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode); @@ -212,6 +227,10 @@ struct tizen_input_device_manager_listener _wl_tz_devmgr_listener = _cb_block_expired }; +struct tizen_display_policy_listener _wl_tz_display_policy_listener = +{ + _cb_wl_tz_display_policy_brightness_done, +}; #endif /* end of WAYLAND */ static Eina_Bool @@ -517,6 +536,18 @@ _cb_wl_reg_global(void *data, _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version); tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL); } + else if (!strcmp(interface, "tizen_display_policy")) + { + _eflutil.wl.display_policy.proto = wl_registry_bind(reg, name, &tizen_display_policy_interface, version); + if (!_eflutil.wl.display_policy.proto) return; + + tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto, + &_wl_tz_display_policy_listener, + NULL); + + _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free); + } + } static void @@ -527,6 +558,9 @@ _cb_wl_reg_global_remove(void *data, _eflutil.wl.policy.proto = NULL; eina_hash_free(_eflutil.wl.policy.hash_noti_lv); eina_hash_free(_eflutil.wl.policy.hash_scr_mode); + + _eflutil.wl.display_policy.proto = NULL; + eina_hash_free(_eflutil.wl.display_policy.hash_brightness); } static Efl_Util_Callback_Info * @@ -639,6 +673,24 @@ static void _cb_wl_tz_policy_allowed_aux_hint(void *data, str } static void +_cb_wl_tz_display_policy_brightness_done(void *data, + struct tizen_display_policy *tizen_display_policy, + struct wl_surface *surface, + int32_t brightness, + uint32_t state) +{ + Efl_Util_Wl_Surface_Brightness_Info *brightness_info; + + brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface); + if (brightness_info) + { + brightness_info->brightness = brightness; + brightness_info->wait_for_done = EINA_FALSE; + brightness_info->state = state; + } +} + +static void _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { Efl_Util_Wl_Surface_Lv_Info *lv_info; @@ -1233,6 +1285,126 @@ efl_util_unset_window_screen_mode_error_cb(Evas_Object *window) return EFL_UTIL_ERROR_NONE; } +API int +efl_util_set_window_brightness(Evas_Object *window, int brightness) +{ + Ecore_Wl_Window *wlwin; + struct wl_surface *surface; + Efl_Util_Wl_Surface_Brightness_Info *brightness_info; + Eina_Bool res; + + EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(brightness <= 100, EFL_UTIL_ERROR_INVALID_PARAMETER); + + res = _wl_init(); + EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); + + wlwin = elm_win_wl_window_get(window); + if (wlwin) + { + while (!_eflutil.wl.display_policy.proto) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + surface = ecore_wl_window_surface_get(wlwin); + EINA_SAFETY_ON_NULL_RETURN_VAL(surface, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface); + if (!brightness_info) + { + brightness_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Brightness_Info)); + EINA_SAFETY_ON_NULL_RETURN_VAL(brightness_info, EFL_UTIL_ERROR_OUT_OF_MEMORY); + + brightness_info->surface = surface; + brightness_info->brightness = brightness; + brightness_info->wait_for_done = EINA_TRUE; + brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE; + + eina_hash_add(_eflutil.wl.display_policy.hash_brightness, + &surface, + brightness_info); + } + else + { + brightness_info->brightness = brightness; + brightness_info->wait_for_done = EINA_TRUE; + brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE; + } + + tizen_display_policy_set_window_brightness(_eflutil.wl.display_policy.proto, + surface, brightness); + if (brightness_info->wait_for_done) + { + int count = 0; + while (brightness_info->wait_for_done && (count < 3)) + { + ecore_wl_flush(); + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + count++; + } + + if (brightness_info->wait_for_done) + { + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + else + { + if (brightness_info->state == TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED) + { + return EFL_UTIL_ERROR_PERMISSION_DENIED; + } + } + } + return EFL_UTIL_ERROR_NONE; + } + else + return EFL_UTIL_ERROR_INVALID_PARAMETER; +} + +API int +efl_util_get_window_brightness(Evas_Object *window, int *brightness) +{ + Ecore_Wl_Window *wlwin; + struct wl_surface *surface; + Efl_Util_Wl_Surface_Brightness_Info *brightness_info; + Eina_Bool res; + + EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(brightness, EFL_UTIL_ERROR_INVALID_PARAMETER); + + res = _wl_init(); + EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); + + wlwin = elm_win_wl_window_get(window); + if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER; + + while (!_eflutil.wl.display_policy.proto) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + surface = ecore_wl_window_surface_get(wlwin); + EINA_SAFETY_ON_NULL_RETURN_VAL(surface, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface); + if (brightness_info) + { + if (brightness_info->wait_for_done) + { + while (brightness_info->wait_for_done) + { + ecore_wl_flush(); + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + } + } + *brightness = brightness_info->brightness; + } + else + *brightness = -1; + + return EFL_UTIL_ERROR_NONE; +} + + struct _efl_util_inputgen_h { unsigned int init_type;