From 9fe96f374acc856e088e0985a4cb07298ec05744 Mon Sep 17 00:00:00 2001 From: "Wonsik, Jung" Date: Thu, 1 Dec 2016 21:52:04 +0900 Subject: [PATCH] [SDL_Tizen] Add PreRotation feature Add PreRotation feature when device support that Change-Id: I097eee032bbd0b8a2e80e7d62e393fb2c547711c --- src/core/tizen/SDL_tizen.c | 2 +- src/video/tizen/SDL_tizenopengles.c | 5 +- src/video/tizen/SDL_tizenwindow.c | 139 +++++++++++++++++++++++++++++------- src/video/tizen/SDL_tizenwindow.h | 2 + 4 files changed, 120 insertions(+), 28 deletions(-) diff --git a/src/core/tizen/SDL_tizen.c b/src/core/tizen/SDL_tizen.c index bc94d4b..c8a04c2 100644 --- a/src/core/tizen/SDL_tizen.c +++ b/src/core/tizen/SDL_tizen.c @@ -230,7 +230,7 @@ SDL_tizen_app_init(int argc, char *argv[]) ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, _tizen_app_low_battery, NULL); ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, _tizen_app_low_memory, NULL); - ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, _tizen_app_orient_changed, NULL); +// ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, _tizen_app_orient_changed, NULL); ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _tizen_app_lang_changed, NULL); ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, _tizen_app_region_changed, NULL); diff --git a/src/video/tizen/SDL_tizenopengles.c b/src/video/tizen/SDL_tizenopengles.c index 9928633..c2b6630 100755 --- a/src/video/tizen/SDL_tizenopengles.c +++ b/src/video/tizen/SDL_tizenopengles.c @@ -513,7 +513,10 @@ int Indicator_GLES_Init(SDL_Window* window) wind->last_indicator_showtime = SDL_GetTicks(); ecore_main_loop_iterate(); - SDL_IndicatorProcessEvent(window, wind->rotation); + if (!wind->support_pre_rotation) + SDL_IndicatorProcessEvent(window, wind->rotation); + else + SDL_IndicatorProcessEvent(window, 0); _tizen_indicator_event_filter(); diff --git a/src/video/tizen/SDL_tizenwindow.c b/src/video/tizen/SDL_tizenwindow.c index 4df67c5..1dbdabd 100755 --- a/src/video/tizen/SDL_tizenwindow.c +++ b/src/video/tizen/SDL_tizenwindow.c @@ -77,7 +77,36 @@ Tizen_SetWindowFullscreen(_THIS, SDL_Window *window, /*DO NOTHING*/ } -static void +void +_tizen_pre_rotation_set(struct wl_egl_window *win, int angle) +{ + wl_egl_window_rotation rot; + if (!win) return; + + SDL_Log("%s with angle %d",__FUNCTION__, angle); + switch (angle) { + case 270: + rot = ROTATION_270; + break; + case 180: + rot = ROTATION_180; + break; + case 90: + rot = ROTATION_90; + break; + case 0: + rot = ROTATION_0; + break; + default: + rot = ROTATION_0; + break; + } + + SDL_SetError("call wl_egl_win_set_rotation with rot %d",rot); + wl_egl_window_set_rotation(win, rot); +} + +void _tizen_window_orientaiton_hint_callback(void *userdata, const char *name, const char *oldValue, const char *newValue) { char *p_str = NULL; @@ -88,8 +117,7 @@ _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; } @@ -134,12 +162,17 @@ _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); + SDL_Log("SDL %s: support pre_rotation %d", __FUNCTION__,wind->support_pre_rotation); + if (wind->support_pre_rotation) { + SDL_Log("SDL %s: set pre rotation %d", __FUNCTION__,wind->rotation); + _tizen_pre_rotation_set(wind->egl_window, wind->rotation); + } } ecore_wl_window_rotation_available_rotations_set(window, (const int*)checked, j); } } -static void +void _tizen_window_orientation_add_hint(void *data) { SDL_WindowData *wind = (SDL_WindowData*)data; @@ -203,6 +236,17 @@ Tizen_CreateWindow(_THIS, SDL_Window *window) SDL_SetError("failed to create a window surface"); return -1; } + + //Support PreRotation + wind->support_pre_rotation = 0; + SDL_Log("SDL %s: call wl_egl_window_get_capabilities()", __FUNCTION__); + if (wl_egl_window_get_capabilities(wind->egl_window) == WL_EGL_WINDOW_CAPABILITY_ROTATION_SUPPORTED ) { + wind->support_pre_rotation = 1; + SDL_Log("Can support PreRotation"); + } + else { + SDL_Log("can not support PreRotation !!!!!!!!!!!!!!"); + } } #endif @@ -234,17 +278,16 @@ Tizen_CreateWindow(_THIS, SDL_Window *window) } void -_tizen_setwindowsize(SDL_Window *window, int update_egl) +_tizen_egl_window_resize(SDL_Window *window) { SDL_WindowData *wind = window->driverdata; - if (!wind->window) - { + if (!wind->egl_window) { return; } // TODO : consider to rotation status. #if SDL_VIDEO_OPENGL_EGL - if ((window->flags & SDL_WINDOW_OPENGL) && (update_egl == 1)) { + if (window->flags & SDL_WINDOW_OPENGL) { int aw, ah, dx = 0, dy = 0; if ((wind->rotation == 90) || (wind->rotation == 270)) @@ -258,13 +301,24 @@ _tizen_setwindowsize(SDL_Window *window, int update_egl) wl_egl_window_resize(wind->egl_window, window->w, window->h, dx, dy); } #endif + +} + +void +_tizen_setwindowsize(SDL_Window *window) +{ + SDL_WindowData *wind = window->driverdata; + if (!wind->window) { + return; + } ecore_wl_window_update_size(wind->window, window->w, window->h); } void Tizen_SetWindowSize(_THIS, SDL_Window *window) { - _tizen_setwindowsize(window, 1); + _tizen_setwindowsize(window); + _tizen_egl_window_resize(window); } void @@ -283,15 +337,10 @@ Tizen_GetWindowSize(_THIS, SDL_Window *window, int *w, int *h) tmp_h = window->w; } - if (w) { - *w = tmp_w; - } - if (h) { - *h = tmp_h; - } + if (w) *w = tmp_w; + if (h) *h = tmp_h; } - void Tizen_SetWindowPosition(_THIS, SDL_Window * window) { @@ -335,7 +384,7 @@ Tizen_FindWindow(_THIS, Ecore_Wl_Window *ewin) return (SDL_Window*)eina_hash_find(data->windows, &id); } -static Eina_Bool +Eina_Bool _tizen_cb_event_window_visibility_change(void *data, int type, void *event) { _THIS = data; @@ -354,7 +403,7 @@ _tizen_cb_event_window_visibility_change(void *data, int type, void *event) return ECORE_CALLBACK_PASS_ON; } -static Eina_Bool +Eina_Bool _tizen_cb_window_configure(void *data, int type EINA_UNUSED, void *event) { _THIS = data; @@ -385,12 +434,33 @@ _tizen_cb_window_configure(void *data, int type EINA_UNUSED, void *event) window->w = nw; window->h = nh; - _tizen_setwindowsize(window, 0); + _tizen_setwindowsize(window); } return ECORE_CALLBACK_PASS_ON; } -static Eina_Bool + +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; +} + +Eina_Bool _tizen_cb_event_window_rotate(void *data, int type EINA_UNUSED, void *event) { _THIS = data; @@ -412,11 +482,25 @@ _tizen_cb_event_window_rotate(void *data, int type EINA_UNUSED, void *event) /* set ecore_wayland window rotation */ wind->rotation = ev->angle; ecore_wl_window_rotation_set(ew, ev->angle); - _tizen_setwindowsize(window, 1); - if (wind->rotation == 0 || wind->rotation == 180) - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h); - else if (wind->rotation == 90 || wind->rotation == 270) - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->h, window->w); + + // support prerotation + /* set ecore_wayland window rotation */ + _tizen_setwindowsize(window); + + if(!wind->support_pre_rotation) { + _tizen_egl_window_resize(window); + } + else { + _tizen_pre_rotation_set(wind->egl_window, (int)ev->angle); + } + + // Send Rotation Event + _tizen_send_rotation_event(window, ev->angle); + + if (wind->rotation == 0 || wind->rotation == 180) + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h); + else if (wind->rotation == 90 || wind->rotation == 270) + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->h, window->w); } wind->received_rotation = 1; @@ -425,7 +509,10 @@ _tizen_cb_event_window_rotate(void *data, int type EINA_UNUSED, void *event) { if(*hint != '\0') { - SDL_IndicatorProcessEvent(_this->current_glwin, wind->rotation); + if (!wind->support_pre_rotation) + SDL_IndicatorProcessEvent(_this->current_glwin, wind->rotation); + else + SDL_IndicatorProcessEvent(_this->current_glwin, 0); } } diff --git a/src/video/tizen/SDL_tizenwindow.h b/src/video/tizen/SDL_tizenwindow.h index 1defe7d..abc14dc 100755 --- a/src/video/tizen/SDL_tizenwindow.h +++ b/src/video/tizen/SDL_tizenwindow.h @@ -46,6 +46,8 @@ typedef struct { SDL_bool indicator_show; Uint32 last_indicator_showtime; + int support_pre_rotation; + } SDL_WindowData; -- 2.7.4