[SDL_Tizen] Fix rotation issue
[platform/upstream/SDL.git] / src / video / tizen / SDL_tizenwindow.c
index 8821f79..9d0b26d 100755 (executable)
@@ -63,9 +63,6 @@ if (!_this->tizen_pre_rotation_data->NAME) \
 }
 
 /*SDL indicator*/
-
-
-
 Ecore_Ipc_Server *ipc = NULL;
 
 #define IPC_HEAD(_type) \
@@ -251,6 +248,13 @@ Tizen_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
 }
 
 void
+Tizen_SetWindowTitle(_THIS, SDL_Window * window)
+{
+    SDL_WindowData *wind = window->driverdata;
+    ecore_wl_window_title_set(wind->window, window->title);
+}
+
+void
 Tizen_ShowWindow(_THIS, SDL_Window *window)
 {
     SDL_WindowData *wind = window->driverdata;
@@ -263,6 +267,20 @@ Tizen_ShowWindow(_THIS, SDL_Window *window)
 }
 
 void
+Tizen_HideWindow(_THIS, SDL_Window *window)
+{
+    SDL_WindowData *wind = window->driverdata;
+    ecore_wl_window_hide(wind->window);
+}
+
+void
+Tizen_RaiseWindow(_THIS, SDL_Window *window)
+{
+    SDL_WindowData *wind = window->driverdata;
+    ecore_wl_window_raise(wind->window);
+}
+
+void
 Tizen_SetWindowFullscreen(_THIS, SDL_Window *window,
                           SDL_VideoDisplay *_display, SDL_bool fullscreen)
 {
@@ -297,6 +315,126 @@ Tizen_pre_rotation_set(SDL_WindowData *_this, int rotation)
 }
 
 void
+_tizen_set_window_size(SDL_Window * window, int w, int h)
+{
+    if(!window)
+    {
+        SDL_SetError("Invalid window");
+        return;
+    }
+
+    SDL_VideoDevice *_this = SDL_GetVideoDevice();
+    if (!_this) {
+        SDL_SetError("Video subsystem has not been initialized");
+        return;
+    }
+
+    if (window->magic != &_this->window_magic) {
+        return;
+    }
+
+    if (w <= 0) {
+        SDL_InvalidParamError("w");
+        return;
+    }
+    if (h <= 0) {
+        SDL_InvalidParamError("h");
+        return;
+    }
+
+    /* Make sure we don't exceed any window size limits */
+    if (window->min_w && w < window->min_w)
+    {
+        w = window->min_w;
+    }
+    if (window->max_w && w > window->max_w)
+    {
+        w = window->max_w;
+    }
+    if (window->min_h && h < window->min_h)
+    {
+        h = window->min_h;
+    }
+    if (window->max_h && h > window->max_h)
+    {
+        h = window->max_h;
+    }
+
+    window->windowed.w = w;
+    window->windowed.h = h;
+
+    window->w = w;
+    window->h = h;
+}
+
+void
+_tizen_send_rotation_event(SDL_Window *window, unsigned int angle)
+{
+    SDL_Event event;
+    SDL_WindowData *wind;
+    wind = window->driverdata;
+
+    SDL_memset(&event, 0, sizeof(event));
+    event.type = SDL_ROTATEEVENT;
+    event.user.code = 0;
+    if (wind->support_pre_rotation)
+        event.user.data1 = (void*)0;
+    else
+        event.user.data1 = (void*)angle;
+    event.user.data2 = (void*)-1;
+
+    SDL_PushEvent(&event);
+    return;
+}
+
+void
+_tizen_rotation_do(SDL_Window *window, SDL_WindowData* wind, int rotation)
+{
+    int window_w, window_h;
+    if(wind->rotation == 0 || wind->rotation == 180)
+        ecore_wl_window_geometry_get(wind->window, 0, 0, &window_w, &window_h);
+    else
+        ecore_wl_window_geometry_get(wind->window, 0, 0, &window_h, &window_w);
+
+    _tizen_set_window_size(window, window_w, window_h);
+
+    if(wind->support_pre_rotation)
+        Tizen_pre_rotation_set(wind, rotation);
+
+    _tizen_send_rotation_event(window, wind->rotation);
+    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
+
+}
+
+void
+Tizen_rotate_update(SDL_Window *window)
+{
+    SDL_WindowData *wind = window->driverdata;
+    if(!wind) return;
+
+    int screen_rotation;
+    if (ecore_wl_window_ignore_output_transform_get(wind->window))
+    {
+        screen_rotation = 0;
+    }
+    else
+    {
+        Ecore_Wl_Output *output = ecore_wl_window_output_find(wind->window);
+        screen_rotation = ecore_wl_output_transform_get(output) * 90;
+    }
+
+    //Set Screen Rotation
+    wind->output_rotation = screen_rotation;
+    if(wind->support_pre_rotation)
+        ecore_wl_window_buffer_transform_set(wind->window, wind->output_rotation / 90);
+
+    ecore_wl_window_rotation_set(wind->window, wind->rotation);
+
+    int rotation = (wind->output_rotation + wind->rotation) % 360;
+    _tizen_rotation_do(window, wind, rotation);
+}
+
+void
 _tizen_window_orientaiton_hint_callback(void *userdata, const char *name, const char *oldValue, const char *newValue)
 {
     char *p_str = NULL;
@@ -307,15 +445,13 @@ _tizen_window_orientaiton_hint_callback(void *userdata, const char *name, const
     SDL_WindowData *wind = (SDL_WindowData*)userdata;
     Ecore_Wl_Window *window = wind->window;
 
-    if (wind->rotation_supported == 0) {
+    if (wind->rotation_supported == 0)
         return;
-    }
 
     SDL_assert(SDL_strncmp(name, SDL_HINT_ORIENTATIONS, SDL_strlen(SDL_HINT_ORIENTATIONS)) == 0);
 
-    if ((oldValue == NULL) && (newValue == NULL)) {
+    if ((oldValue == NULL) && (newValue == NULL))
         return;
-    }
 
     for (i=0;i<4;i++) {
         p_str = SDL_strstr(newValue, orientation_type[i]);
@@ -347,20 +483,21 @@ _tizen_window_orientaiton_hint_callback(void *userdata, const char *name, const
 
     if (j > 0) {
         if (j == 1) {
-            ecore_wl_window_rotation_preferred_rotation_set(window,wind->rotation);
+            ecore_wl_window_rotation_preferred_rotation_set(window, wind->rotation);
         }else {
             ecore_wl_window_rotation_available_rotations_set(window, (const int*)checked, j);
         }
     }
+
+    Tizen_rotate_update(Tizen_FindWindow(SDL_GetVideoDevice(), window));
 }
 
 void
 _tizen_window_orientation_add_hint(void *data)
 {
     SDL_WindowData *wind = (SDL_WindowData*)data;
-    if (wind->rotation_supported == 0) {
+    if (wind->rotation_supported == 0)
         return;
-    }
 
     SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, _tizen_window_orientaiton_hint_callback, data);
 }
@@ -410,131 +547,6 @@ _tizen_output_transform_register(SDL_WindowData *wind)
                              _tizen_cb_output_transform, NULL);
     ecore_event_handler_add(ECORE_WL_EVENT_IGNORE_OUTPUT_TRANSFORM,
                              _tizen_cb_ignore_output_transform, NULL);
-
-}
-
-void
-_tizen_send_rotation_event(SDL_Window *window, unsigned int angle)
-{
-    SDL_Event event;
-    SDL_WindowData *wind;
-    wind = window->driverdata;
-
-    SDL_memset(&event, 0, sizeof(event));
-    event.type = SDL_ROTATEEVENT;
-    event.user.code = 0;
-    if (wind->support_pre_rotation)
-        event.user.data1 = (void*)0;
-    else
-        event.user.data1 = (void*)angle;
-    event.user.data2 = (void*)-1;
-
-    SDL_PushEvent(&event);
-    return;
-}
-
-void
-_tizen_set_window_size(SDL_Window * window, int w, int h)
-{
-    if(!window)
-    {
-        SDL_SetError("Invalid window");
-        return;
-    }
-
-    SDL_VideoDevice *_this = SDL_GetVideoDevice();
-    if (!_this) {
-        SDL_SetError("Video subsystem has not been initialized");
-        return;
-    }
-
-    if (window->magic != &_this->window_magic) {
-        return;
-    }
-
-    if (w <= 0) {
-        SDL_InvalidParamError("w");
-        return;
-    }
-    if (h <= 0) {
-        SDL_InvalidParamError("h");
-        return;
-    }
-
-    /* Make sure we don't exceed any window size limits */
-    if (window->min_w && w < window->min_w)
-    {
-        w = window->min_w;
-    }
-    if (window->max_w && w > window->max_w)
-    {
-        w = window->max_w;
-    }
-    if (window->min_h && h < window->min_h)
-    {
-        h = window->min_h;
-    }
-    if (window->max_h && h > window->max_h)
-    {
-        h = window->max_h;
-    }
-
-    window->windowed.w = w;
-    window->windowed.h = h;
-
-    window->w = w;
-    window->h = h;
-}
-
-void
-_tizen_rotation_do(SDL_WindowData *wind, int rotation)
-{
-    if(!wind) return;
-
-    SDL_Window *window = SDL_GetVideoDevice()->windows;
-    if(!window) return;
-
-    int window_w, window_h;
-    if(wind->rotation == 0 || wind->rotation == 180)
-        ecore_wl_window_geometry_get(wind->window, 0, 0, &window_w, &window_h);
-    else
-        ecore_wl_window_geometry_get(wind->window, 0, 0, &window_h, &window_w);
-
-    _tizen_set_window_size(window, window_w, window_h);
-
-    if(wind->support_pre_rotation)
-        Tizen_pre_rotation_set(wind, rotation);
-
-    _tizen_send_rotation_event(window, wind->rotation);
-    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
-
-}
-
-void
-_tizen_rotate_update(SDL_WindowData *wind)
-{
-    if(!wind) return;
-
-    int screen_rotation;
-    if (ecore_wl_window_ignore_output_transform_get(wind->window))
-    {
-        screen_rotation = 0;
-    }
-    else
-    {
-        Ecore_Wl_Output *output = ecore_wl_window_output_find(wind->window);
-        screen_rotation = ecore_wl_output_transform_get(output) * 90;
-    }
-
-    //Set Screen Rotation
-    wind->output_rotation = screen_rotation;
-    if(wind->support_pre_rotation)
-        ecore_wl_window_buffer_transform_set(wind->window, wind->output_rotation / 90);
-
-    ecore_wl_window_rotation_set(wind->window, wind->rotation);
-
-    int rotation = (wind->output_rotation + wind->rotation) % 360;
-    _tizen_rotation_do(wind, rotation);
 }
 
 int
@@ -661,7 +673,7 @@ Tizen_CreateWindow(_THIS, SDL_Window *window)
     // Add orientaiton hint cb
     _tizen_window_orientation_add_hint((void*)wind);
 
-    _tizen_rotate_update(wind);
+    Tizen_rotate_update(window);
 
     return 0;
 }
@@ -671,18 +683,15 @@ Tizen_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
 {
     SDL_WindowData *wind = window->driverdata;
     if(!wind->indicator)
-    {
         SDL_ExecuteIndicatorProcess();
-    }
 }
 
 void
-_tizen_window_resize(SDL_Window *window)
+Tizen_SetWindowSize(_THIS, SDL_Window *window)
 {
     SDL_WindowData *wind = window->driverdata;
-    if (!wind->egl_window) {
+    if (!wind->egl_window)
         return;
-    }
 
     if(wind->support_pre_rotation && (wind->rotation==90 || wind->rotation==270))
         ecore_wl_window_update_size(wind->window, window->h, window->w);
@@ -690,29 +699,15 @@ _tizen_window_resize(SDL_Window *window)
         ecore_wl_window_update_size(wind->window, window->w, window->h);
 
     // TODO : consider to rotation status.
-#if SDL_VIDEO_OPENGL_EGL
+    #if SDL_VIDEO_OPENGL_EGL
     if (window->flags & SDL_WINDOW_OPENGL) {
-      if(wind->output_rotation==90 || wind->output_rotation==270)
-          wl_egl_window_resize(wind->egl_window, window->h, window->w, 0, 0);
-      else
-          wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
-    }
-#endif
-}
-
-void
-_tizen_setwindowsize(SDL_Window *window)
-{
-    SDL_WindowData *wind = window->driverdata;
-    if (!wind->window) {
-        return;
+        if(wind->output_rotation==90 || wind->output_rotation==270)
+            wl_egl_window_resize(wind->egl_window, window->h, window->w, 0, 0);
+        else
+            wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
     }
-}
+    #endif
 
-void
-Tizen_SetWindowSize(_THIS, SDL_Window *window)
-{
-    _tizen_window_resize(window);
 }
 
 void
@@ -803,26 +798,10 @@ _tizen_cb_window_configure(void *data, int type EINA_UNUSED, void *event)
    if (wind->rotation_supported == 0){
       return ECORE_CALLBACK_PASS_ON;
    }
-/*
-   int nx = 0, ny = 0, nw = 0, nh = 0;
-  SDL_Log( "configure notify window: %p, ecore_wl_window: %p\n", window, ew);
-
-   ecore_wl_window_geometry_get(ew, &nx, &ny, &nw, &nh);
-   if (nw < 1) nw = 1;
-   if (nh < 1) nh = 1;
-   
-   SDL_Log("[SDL_Size] * _tizen_cb_window_configure :: w->w:%d, w->h:%d, nw:%d, nh:%d", window->w, window->h, nw, nh);
-   if ((window->x != nx) || (window->y != ny))
-     ecore_wl_window_position_set(ew, nx, ny);
-
-   if ((window->w != nw) || (window->h != nh)) {
-     _tizen_setwindowsize(window);
-   }
-   */
+
    return ECORE_CALLBACK_PASS_ON;
 }
 
-
 Eina_Bool
 _tizen_cb_event_window_rotate(void *data, int type EINA_UNUSED, void *event)
 {
@@ -859,31 +838,35 @@ Tizen_InitWindow(_THIS)
 
     ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
                         _tizen_cb_event_window_visibility_change,_this);
+    ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_ROTATE,
+                        _tizen_cb_event_window_rotate,_this);
+    ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_CONFIGURE,
+                        _tizen_cb_window_configure,_this);
+
     ecore_event_handler_add(ECORE_EVENT_KEY_UP,
                         _tizen_cb_event_keyup_change,_this);
     ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
                         _tizen_cb_event_keydown_change,_this);
+
     ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
                         _tizen_cb_event_mousedown_change,_this);
     ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
                         _tizen_cb_event_mouseup_change,_this);
     ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE,
                         _tizen_cb_event_mousemove_change,_this);
-    ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_ROTATE,
-                        _tizen_cb_event_window_rotate,_this);
-    ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_CONFIGURE,
-                        _tizen_cb_window_configure,_this);
-    ecore_event_handler_add(ECORE_EVENT_JOYSTICK,
-                        _tizen_cb_event_joystick_change,_this);
-    ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN,
-                        _tizen_cb_event_focus_in,_this);
-    ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT,
-                        _tizen_cb_event_focus_out,_this);
     ecore_event_handler_add(ECORE_WL_EVENT_MOUSE_IN,
                         _tizen_cb_event_mouse_in,_this);
     ecore_event_handler_add(ECORE_WL_EVENT_MOUSE_OUT,
                         _tizen_cb_event_mouse_out,_this);
 
+    ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN,
+                        _tizen_cb_event_focus_in,_this);
+    ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT,
+                        _tizen_cb_event_focus_out,_this);
+
+    ecore_event_handler_add(ECORE_EVENT_JOYSTICK,
+                        _tizen_cb_event_joystick_change,_this);
+
     return 0;
 }