Merge "[SDL_Tizen] Fix rotation issue" into tizen
[platform/upstream/SDL.git] / src / video / tizen / SDL_tizenwindow.c
index 9d0b26d..7811e2f 100755 (executable)
@@ -55,8 +55,8 @@ enum {
 };
 
 #define LOAD_FUNC(NAME) \
-_this->tizen_pre_rotation_data->NAME = SDL_LoadFunction(_this->tizen_pre_rotation_data->prerotation_dll_handle, #NAME); \
-if (!_this->tizen_pre_rotation_data->NAME) \
+_this->tizen_pre_rotation_data.NAME = SDL_LoadFunction(_this->tizen_pre_rotation_data.prerotation_dll_handle, #NAME); \
+if (!_this->tizen_pre_rotation_data.NAME) \
 { \
     SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Could not retrieve pre-rotation function " #NAME); \
     return SDL_FALSE; \
@@ -70,7 +70,7 @@ Ecore_Ipc_Server *ipc = NULL;
    if (ecore_ipc_client_server_get(e->client) != ipc) \
      return ECORE_CALLBACK_PASS_ON
 
-void SDL_ExecuteIndicatorProcess()
+void Tizen_ExecuteIndicatorProcess()
 {
     _tizen_init_ecore_ipc();
     unsigned int childPID = fork();
@@ -78,13 +78,13 @@ void SDL_ExecuteIndicatorProcess()
     {
         SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] child process : %d", getpid());
         int ret = execl("/usr/apps/org.tizen.sdl_indicator/bin/sdl_indicator", "/usr/apps/org.tizen.sdl_indicator/bin/sdl_indicator", NULL);
-        if(ret==-1)
+        if(ret == -1)
         {
             SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Failed indicator process error:%s", strerror(errno));
             kill(getpid(), SIGKILL);
         }
     }
-    else if(childPID==-1)
+    else if(childPID == -1)
     {
         SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Failed fork");
     }
@@ -108,13 +108,17 @@ static Eina_Bool _cb_client_add(void *data EINA_UNUSED, int type EINA_UNUSED, vo
     IPC_HEAD(Add);
 
     SDL_Log("[SDL]_cb_client_add");
+
+    SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
+    videoData->indicator_on = SDL_TRUE;
+
     SDL_Window * window = SDL_GetVideoDevice()->windows;
     SDL_WindowData *wind = window->driverdata;
-    wind->indicator = SDL_TRUE;
 
     int window_w, window_h;
     ecore_wl_screen_size_get(&window_w, &window_h);
-    _tizen_ecore_ipc_client_send(OP_RESIZE, wind->rotation, window_w, window_h);
+
+    _tizen_ecore_ipc_client_send(OP_INDICATOR_SHOW, wind->rotation, 0, videoData->indicator_mode);
 
     return ECORE_CALLBACK_DONE;
 }
@@ -131,9 +135,9 @@ static Eina_Bool _cb_client_del(void *data EINA_UNUSED, int type EINA_UNUSED, vo
         ecore_ipc_client_del(cl);
     }
 
-    SDL_Window * window = SDL_GetVideoDevice()->windows;
-    SDL_WindowData *wind = window->driverdata;
-    wind->indicator = SDL_FALSE;
+    SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
+    videoData->indicator_on = SDL_FALSE;
+
     return ECORE_CALLBACK_DONE;
 }
 
@@ -191,18 +195,19 @@ _tizen_rotation_type_get()
 }
 
 int
-_tizen_PreRotatotion_LoadLibrary(SDL_WindowData *_this, const char *lib_path)
+_tizen_PreRotatotion_LoadLibrary(SDL_VideoData *_this, const char *lib_path)
 {
     void *lib_dll_handle = NULL;
     char *path = NULL;
 
-    if (_this->isLoaded_pre_rotation)
+    if (_this->tizen_pre_rotation_data.prerotation_dll_handle
+        && _this->tizen_pre_rotation_data.wl_egl_window_set_rotation
+        && _this->tizen_pre_rotation_data.wl_egl_window_get_capabilities)
         return SDL_TRUE;
 
-    _this->tizen_pre_rotation_data = (Tizen_Prerotation_Data *) SDL_calloc(1, sizeof(Tizen_Prerotation_Data));
-    if (!_this->tizen_pre_rotation_data) {
-        return SDL_OutOfMemory();
-    }
+    _this->tizen_pre_rotation_data.prerotation_dll_handle = NULL;
+    _this->tizen_pre_rotation_data.wl_egl_window_set_rotation = NULL;
+    _this->tizen_pre_rotation_data.wl_egl_window_get_capabilities = NULL;
 
     if (!lib_path)
         lib_dll_handle = SDL_LoadObject(lib_path);
@@ -212,14 +217,13 @@ _tizen_PreRotatotion_LoadLibrary(SDL_WindowData *_this, const char *lib_path)
         lib_dll_handle = SDL_LoadObject(path);
     }
 
-    _this->tizen_pre_rotation_data->prerotation_dll_handle = lib_dll_handle;
+    _this->tizen_pre_rotation_data.prerotation_dll_handle = lib_dll_handle;
 
     if (lib_dll_handle == NULL)
         return SDL_FALSE;
 
     LOAD_FUNC(wl_egl_window_set_rotation);
     LOAD_FUNC(wl_egl_window_get_capabilities);
-    _this->isLoaded_pre_rotation = 1;
 
     return SDL_TRUE;
 }
@@ -257,12 +261,14 @@ Tizen_SetWindowTitle(_THIS, SDL_Window * window)
 void
 Tizen_ShowWindow(_THIS, SDL_Window *window)
 {
-    SDL_WindowData *wind = window->driverdata;
+    SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
 
-    if(!(window->flags & SDL_WINDOW_FULLSCREEN) && !(window->flags & SDL_WINDOW_BORDERLESS) && !wind->indicator)
+    if(!(window->flags & SDL_WINDOW_FULLSCREEN) && !(window->flags & SDL_WINDOW_BORDERLESS) && !videoData->indicator_on)
     {
-        SDL_ExecuteIndicatorProcess();
+        Tizen_ExecuteIndicatorProcess();
     }
+
+    SDL_WindowData *wind = window->driverdata;
     ecore_wl_window_show(wind->window);
 }
 
@@ -288,10 +294,10 @@ Tizen_SetWindowFullscreen(_THIS, SDL_Window *window,
 }
 
 void
-Tizen_pre_rotation_set(SDL_WindowData *_this, int rotation)
+Tizen_pre_rotation_set(SDL_WindowData *wind, int rotation)
 {
     tizen_wl_egl_window_rotation rot;
-    if (!_this->egl_window) return;
+    if (!wind->egl_window) return;
 
     switch (rotation) {
          case 90:
@@ -311,7 +317,8 @@ Tizen_pre_rotation_set(SDL_WindowData *_this, int rotation)
             break;
       }
 
-      _this->tizen_pre_rotation_data->wl_egl_window_set_rotation(_this->egl_window, rot);
+    SDL_VideoData* _this = SDL_GetVideoDevice()->driverdata;
+    _this->tizen_pre_rotation_data.wl_egl_window_set_rotation(wind->egl_window, rot);
 }
 
 void
@@ -549,6 +556,25 @@ _tizen_output_transform_register(SDL_WindowData *wind)
                              _tizen_cb_ignore_output_transform, NULL);
 }
 
+void
+_tizen_indicator_opacity_hint_callback(void *userdata, const char *name, const char *oldValue, const char *newValue)
+{
+    SDL_VideoData *data = (SDL_VideoData *)userdata;
+
+    if ((oldValue == NULL) && (newValue == NULL))
+        return;
+
+    SDL_assert(SDL_strncmp(name, SDL_HINT_TIZEN_INDICATOR_OPACITY, SDL_strlen(SDL_HINT_TIZEN_INDICATOR_OPACITY)) == 0);
+    char indicator_type[4][20] = {"opaque","translucent","transparent","bg_transparent"};
+    for (int i=0;i<4;i++) {
+        if(SDL_strncmp(newValue, indicator_type[i], SDL_strlen(indicator_type[i])) == 0)
+        {
+            data->indicator_mode = i+1;
+            break;
+        }
+    }
+}
+
 int
 Tizen_CreateWindow(_THIS, SDL_Window *window)
 {
@@ -640,8 +666,8 @@ Tizen_CreateWindow(_THIS, SDL_Window *window)
 
         //Support PreRotation
         wind->support_pre_rotation = 0;
-        if (_tizen_rotation_type_get() && _tizen_PreRotatotion_LoadLibrary(wind, "libwayland-egl.so")) {
-            if (wind->tizen_pre_rotation_data->wl_egl_window_get_capabilities(wind->egl_window) == TIZEN_WL_EGL_WINDOW_CAPABILITY_ROTATION_SUPPORTED ) {
+        if (_tizen_rotation_type_get() && _tizen_PreRotatotion_LoadLibrary(data, "libwayland-egl.so")) {
+            if (data->tizen_pre_rotation_data.wl_egl_window_get_capabilities(wind->egl_window) == TIZEN_WL_EGL_WINDOW_CAPABILITY_ROTATION_SUPPORTED ) {
                 wind->support_pre_rotation = 1;
             }
         }
@@ -672,6 +698,7 @@ Tizen_CreateWindow(_THIS, SDL_Window *window)
       }
     // Add orientaiton hint cb
     _tizen_window_orientation_add_hint((void*)wind);
+    SDL_AddHintCallback(SDL_HINT_TIZEN_INDICATOR_OPACITY, _tizen_indicator_opacity_hint_callback, data);
 
     Tizen_rotate_update(window);
 
@@ -681,9 +708,9 @@ Tizen_CreateWindow(_THIS, SDL_Window *window)
 void
 Tizen_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
 {
-    SDL_WindowData *wind = window->driverdata;
-    if(!wind->indicator)
-        SDL_ExecuteIndicatorProcess();
+    SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
+    if(!videoData->indicator_on)
+        Tizen_ExecuteIndicatorProcess();
 }
 
 void