Sync with the latest tizen 2.x
[apps/native/widget/widget.git] / src / binder.c
index 09fac0e..c71329a 100644 (file)
@@ -2,13 +2,15 @@
 #include <stdlib.h>
 #define __USE_GNU
 #include <dlfcn.h>
+#define _GNU_SOURCE
+#include <string.h>
 
 #include <Elementary.h>
 #include <Ecore_Evas.h>
 
+#include <widget_errno.h>
 #include <widget_service.h>
 #include <widget_service_internal.h>
-#include <widget_errno.h>
 #include <widget_provider.h>
 #include <widget_provider_buffer.h>
 #include <widget_conf.h>
@@ -34,6 +36,7 @@ static struct info {
        int (*add_pre_callback)(widget_pre_callback_e type, widget_pre_callback_t cb, void *data);
        int (*del_pre_callback)(widget_pre_callback_e type, widget_pre_callback_t cb, void *data);
        int (*orientation)(const char *id);
+       int (*get_last_ctrl_mode)(const char *id, int *cmd, int *value);
        Ecore_Evas *(*alloc_canvas)(int w, int h, void *(*a)(void *data, int size), void (*f)(void *data, void *ptr), void *data);
        Ecore_Evas *(*alloc_canvas_with_stride)(int w, int h, void *(*a)(void *data, int size, int *stride, int *bpp), void (*f)(void *data, void *ptr), void *data);
        Ecore_Evas *(*alloc_canvas_with_pixmap)(const char *disp_name, Ecore_X_Window parent, int x, int y, int w, int h, Ecore_X_Pixmap (*alloc_cb)(void *data, Ecore_X_Window parent, int w, int h, int depth), void (*free_cb)(void *data, Ecore_X_Pixmap pixmap), void *data);
@@ -61,6 +64,7 @@ static struct info {
        .add_pre_callback = NULL,
        .del_pre_callback = NULL,
        .orientation = NULL,
+       .get_last_ctrl_mode = NULL,
        .alloc_canvas = NULL,
        .alloc_canvas_with_stride = NULL,
        .alloc_canvas_with_pixmap = NULL,
@@ -82,11 +86,12 @@ static struct info {
 #define FUNC_WIDGET_TRIGGER_UPDATE_MONITOR        FUNC_PREFIX "trigger_update_monitor"
 #define FUNC_WIDGET_UPDATE_EXTRA_INFO             FUNC_PREFIX "update_extra_info"
 
-#define FUNC_WIDGET_PROVIDER_APP_UPDATED          FUNC_PREFIX "provider_app_buffer_updated"
+#define FUNC_WIDGET_PROVIDER_APP_UPDATED          FUNC_PREFIX "provider_app_send_buffer_updated_event"
 
 #define FUNC_WIDGET_PROVIDER_APP_ADD_PRE_CALLBACK FUNC_PREFIX "provider_app_add_pre_callback"
 #define FUNC_WIDGET_PROVIDER_APP_DEL_PRE_CALLBACK FUNC_PREFIX "provider_app_del_pre_callback"
 #define FUNC_WIDGET_PROVIDER_APP_ORIENTATION      FUNC_PREFIX "provider_app_get_orientation"
+#define FUNC_WIDGET_PROVIDER_APP_LAST_CTRL_MODE   FUNC_PREFIX "provider_app_get_last_ctrl_mode"
 
 static inline void load_ecore_evas_function(void)
 {
@@ -128,6 +133,18 @@ static inline void load_update_function(void)
        }
 }
 
+PUBLIC int widget_get_last_ctrl_mode(const char *id, int *cmd, int *value)
+{
+       if (!s_info.get_last_ctrl_mode) {
+               s_info.get_last_ctrl_mode = dlsym(RTLD_DEFAULT, FUNC_WIDGET_PROVIDER_APP_LAST_CTRL_MODE);
+               if (!s_info.get_last_ctrl_mode) {
+                       return WIDGET_ERROR_NOT_SUPPORTED;
+               }
+       }
+
+       return s_info.get_last_ctrl_mode(id, cmd, value);
+}
+
 PUBLIC int widget_get_orientation(const char *id)
 {
        if (!s_info.orientation) {
@@ -386,9 +403,10 @@ static void free_pixmap_cb(void *data, Ecore_X_Pixmap pixmap)
                }
        }
 
-       if (info->deleted && info->resource_cnt == 0) {
+       if (info->flags.field.deleted && info->resource_cnt == 0) {
                DbgPrint("Destroy buffer handle\n");
 
+               info->state = VWIN_INFO_DESTROYED;
                widget_destroy_buffer(info->handle);
                free(info->resource_array);
                free(info->id);
@@ -488,7 +506,8 @@ static void free_fb(void *data, void *ptr)
                ErrPrint("Failed to release buffer\n");
        }
 
-       if (info->deleted) {
+       if (info->flags.field.deleted) {
+               info->state = VWIN_INFO_DESTROYED;
                widget_destroy_buffer(info->handle);
                free(info->resource_array);
                free(info->id);
@@ -496,6 +515,16 @@ static void free_fb(void *data, void *ptr)
        }
 }
 
+static inline int check_gl_engine(const char *engine)
+{
+       /**
+        * @todo
+        * If the "engine" string going to be changed to more complicated formatted string,
+        * We should replace this with sytanx recognizer (parser).
+        */
+       return !!strcasestr(engine, GL_ENGINE);
+}
+
 Ecore_Evas *binder_ecore_evas_new(vwin_info_t info)
 {
        const char *engine;
@@ -503,10 +532,10 @@ Ecore_Evas *binder_ecore_evas_new(vwin_info_t info)
 
        load_ecore_evas_function();
 
-       engine = elm_config_preferred_engine_get();
+       engine = elm_config_accel_preference_get();
 
-       DbgPrint("Preferred engine: %s (%s)\n", engine, GL_ENGINE);
-       if (engine && !strcmp(engine, GL_ENGINE)) {
+       DbgPrint("Preferred engine: %s (%s or %s)\n", engine, GL_ENGINE, GL_ENGINE_X11);
+       if (engine && check_gl_engine(engine)) {
                if (s_info.alloc_canvas_with_pixmap) {
                        ee = s_info.alloc_canvas_with_pixmap(NULL, 0u, 0, 0, info->w, info->h, alloc_pixmap_cb, free_pixmap_cb, info);
                        if (!ee) {