#include <unistd.h>
#include "watch_control.h"
#include <aul.h>
+#include <efl_util.h>
+#include <Elementary.h>
+#include <system_info.h>
#define API __attribute__((visibility("default")))
#define _D LOGD
#endif
+#define KEY_SCREEN_SHAPE_CIRCLE "http://tizen.org/feature/screen.shape.circle"
+
static int __watch_viewer_initialized = 0;
static int __watch_size_policy = WATCH_POLICY_HINT_EXPAND;
static void __watch_viewer_fini()
{
- if (__win)
+ if (__win) {
evas_object_event_callback_del(__win, EVAS_CALLBACK_RESIZE, __win_resized);
+ __win = NULL;
+ }
screen_connector_toolkit_evas_stop_visibility_notify();
screen_connector_toolkit_evas_fini(SCREEN_CONNECTOR_SCREEEN_TYPE_WATCH);
_D("obj added");
_D("w: %d, h: %d, x: %d y: %d", w, h, x, y);
evas_object_smart_callback_call(__win, WATCH_SMART_SIGNAL_ADDED, image);
+ evas_object_data_set(__win, "tbm,watch", image);
}
static void __screen_connector_toolkit_evas_removed_cb(const char *appid, const char *instance_id, int pid,
{
_D("obj removed");
evas_object_smart_callback_call(__win, WATCH_SMART_SIGNAL_REMOVED, image);
+ evas_object_data_set(__win, "tbm,watch", NULL);
}
static void __screen_connector_toolkit_evas_updated_cb(const char *appid, const char *instance_id, int pid,
return 0;
}
+static float __get_opr(void *source_data, int width, int height)
+{
+ int *source;
+ int x;
+ int y;
+ int idx;
+ int max_rad;
+ int rad;
+ int pos;
+ unsigned int r = 0;
+ unsigned int g = 0;
+ unsigned int b = 0;
+ unsigned int pixel_sum;
+ float opr;
+ float max_opr;
+ bool shape_circle = false;
+
+ system_info_get_platform_bool(KEY_SCREEN_SHAPE_CIRCLE, &shape_circle);
+
+ source = source_data;
+ pos = width / 2;
+ max_rad = (height * height) >> 2;
+
+ for (y = 0; y < height; ++y) {
+ for (x = 0; x < width; ++x) {
+ if (shape_circle) {
+ rad = (pos - x) * (pos - x) + (pos - y) * (pos - y);
+ if (rad <= max_rad) {
+ idx = y * width + x;
+ r += ((source[idx] & 0x00ff0000) >> 16);
+ g += ((source[idx] & 0x0000ff00) >> 8);
+ b += (source[idx] & 0x000000ff);
+ }
+ } else {
+ idx = y * width + x;
+ r += ((source[idx] & 0x00ff0000) >> 16);
+ g += ((source[idx] & 0x0000ff00) >> 8);
+ b += (source[idx] & 0x000000ff);
+ }
+ }
+ }
+
+ if (shape_circle)
+ max_opr = (width / 2) * (height / 2) * 3.14 * 3 * 255;
+ else
+ max_opr = width * height * 3 * 255;
+
+ pixel_sum = r + g + b;
+ opr = ((float)pixel_sum) / max_opr;
+
+ return opr;
+}
+
+API int watch_manager_get_opr(float *opr)
+{
+ Evas_Object *image;
+ efl_util_screenshot_h screenshot;
+ tbm_surface_h surface;
+ tbm_surface_info_s info = { 0, };
+ void *source_data;
+ int width = 0;
+ int height = 0;
+ int ret;
+
+ if (opr == NULL) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (__win == NULL) {
+ _E("Window is NULL");
+ return -1;
+ }
+
+ image = evas_object_data_get(__win, "tbm,watch");
+ if (image == NULL) {
+ _E("Failed to get image");
+ return -1;
+ }
+
+ evas_object_geometry_get(image, NULL, NULL, &width, &height);
+ _D("width(%d), height(%d)", width, height);
+
+ screenshot = efl_util_screenshot_initialize(width, height);
+ if (screenshot == NULL) {
+ _E("Failed to initialize efl util screenshot - %d",
+ get_last_result());
+ return -1;
+ }
+
+ surface = efl_util_screenshot_take_tbm_surface(screenshot);
+ if (surface == NULL) {
+ _E("Failed to take tbm surface - %d", get_last_result());
+ efl_util_screenshot_deinitialize(screenshot);
+ return -1;
+ }
+
+ ret = tbm_surface_map(surface, TBM_SURF_OPTION_READ, &info);
+ if (ret != TBM_SURFACE_ERROR_NONE) {
+ _E("Failed to map tbm surface - %d", ret);
+ tbm_surface_destroy(surface);
+ efl_util_screenshot_deinitialize(screenshot);
+ return -1;
+ }
+
+ source_data = info.planes[0].ptr;
+ if (source_data == NULL) {
+ _E("Failed to get source");
+ tbm_surface_unmap(surface);
+ tbm_surface_destroy(surface);
+ efl_util_screenshot_deinitialize(screenshot);
+ return -1;
+ }
+
+ *opr = __get_opr(source_data, width, height);
+ _D("On Pixel Ratio(%f)", *opr);
+
+ tbm_surface_unmap(surface);
+ tbm_surface_destroy(surface);
+ efl_util_screenshot_deinitialize(screenshot);
+
+ return 0;
+}