From 7227f8271d5b6a0053bcba5f17333bfeb79eb202 Mon Sep 17 00:00:00 2001 From: "Wonsik, Jung" Date: Sun, 25 Sep 2016 12:07:33 +0900 Subject: [PATCH] [SDL_Tizen] Add rotation feature 1. Add rotation feature 2. clean up code Change-Id: I6921bbe0f369558958f10c241b56f50957f48d66 Author: Wonsik, Jung --- configure | 2 + configure.in | 2 + src/core/tizen/SDL_tizen.c | 41 ++--- src/video/SDL_sysvideo.h | 3 + src/video/SDL_video.c | 14 ++ src/video/tizen/SDL_tizenevents.c | 4 +- src/video/tizen/SDL_tizenevents_c.h | 4 +- src/video/tizen/SDL_tizenkeyboard.c | 46 +++--- src/video/tizen/SDL_tizenkeyboard.h | 2 - src/video/tizen/SDL_tizenmouse.c | 6 +- src/video/tizen/SDL_tizenmouse.h | 6 +- src/video/tizen/SDL_tizenopengles.c | 6 + src/video/tizen/SDL_tizenvideo.c | 2 + src/video/tizen/SDL_tizenvulkan.c | 2 - src/video/tizen/SDL_tizenwindow.c | 274 +++++++++++++++++++++++++++++++--- src/video/tizen/SDL_tizenwindow.h | 5 + src/video/wayland/SDL_waylandvulkan.c | 2 - 17 files changed, 335 insertions(+), 86 deletions(-) diff --git a/configure b/configure index 2f5edd4..cf1cdf5 100755 --- a/configure +++ b/configure @@ -21563,6 +21563,8 @@ int main () { + uint32_t instance_layer_count = 0; + vkEnumerateInstanceLayerProperties(&instance_layer_count, NULL); ; return 0; diff --git a/configure.in b/configure.in index f70b39b..9ef9850 100644 --- a/configure.in +++ b/configure.in @@ -2209,6 +2209,8 @@ CheckVulkanTizen() AC_TRY_COMPILE([ #include ],[ + uint32_t instance_layer_count = 0; + vkEnumerateInstanceLayerProperties(&instance_layer_count, NULL); ],[ video_vulkan=yes ]) diff --git a/src/core/tizen/SDL_tizen.c b/src/core/tizen/SDL_tizen.c index 62f628a..23390d1 100644 --- a/src/core/tizen/SDL_tizen.c +++ b/src/core/tizen/SDL_tizen.c @@ -30,13 +30,6 @@ #include #include #include -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif - -#define LOG_TAG "SDL" static int tizen_appcore_initialized = 0; static appcore_context_h appcore_handle = NULL; @@ -50,14 +43,14 @@ static app_event_handler_h handlers[5] = {NULL, }; static bool _tizen_sdl_create(void *data) { - LOGI("SDL_AppCore CreateCB"); + SDL_Log("App Create"); return true; } static void _tizen_sdl_terminate(void *data) { - LOGI("SDL_AppCore TermincateCB"); + SDL_Log("App Termincate"); SDL_SendQuit(); SDL_SendAppEvent(SDL_APP_TERMINATING); return; @@ -66,7 +59,7 @@ _tizen_sdl_terminate(void *data) static void _tizen_sdl_pause (void *data) { - LOGI("SDL_AppCore PauseCB"); + SDL_Log("App Pause"); SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND); SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND); return; @@ -75,7 +68,7 @@ _tizen_sdl_pause (void *data) static void _tizen_sdl_resume(void *data) { - LOGI("SDL_AppCore ResumeCB"); + SDL_Log("App Resume"); SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND); SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND); return; @@ -84,7 +77,7 @@ _tizen_sdl_resume(void *data) static void _tizen_sdl_control(app_control_h app_control, void *data) { - LOGI("SDL_AppCore ControlCB"); + SDL_Log("App Control"); SDL_Event event; SDL_memset(&event, 0, sizeof(event)); @@ -102,7 +95,7 @@ _tizen_app_lang_changed(app_event_info_h event_info, void *user_data) { /*APP_EVENT_LANGUAGE_CHANGED*/ char *locale = NULL; - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Language changedCB"); + SDL_Log("Language changed"); system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale); free(locale); return; @@ -114,13 +107,13 @@ _tizen_app_orient_changed(app_event_info_h event_info, void *user_data) /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/ app_device_orientation_e orientation; app_event_get_device_orientation(event_info, &orientation); - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION," Orientation Changed CB, Rotation Degree : %d", orientation); + SDL_Log("Orientation Changed, Rotation Degree : %d", orientation); SDL_Event event; SDL_memset(&event, 0, sizeof(event)); event.type = SDL_ROTATEEVENT; event.user.code = 0; event.user.data1 = (void*)orientation; - event.user.data2 = -1; + event.user.data2 = (void*)-1; SDL_PushEvent(&event); return; @@ -130,37 +123,35 @@ static void _tizen_app_region_changed(app_event_info_h event_info, void *user_data) { /*APP_EVENT_REGION_FORMAT_CHANGED*/ - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "region changedCB"); + SDL_Log("region changed"); } static void _tizen_app_low_battery(app_event_info_h event_info, void *user_data) { /*APP_EVENT_LOW_BATTERY*/ - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "low battery CB"); + SDL_Log("low battery"); } static void _tizen_app_low_memory(app_event_info_h event_info, void *user_data) { /*APP_EVENT_LOW_MEMORY*/ - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "low memory CB"); + SDL_Log("low memory"); SDL_SendAppEvent(SDL_APP_LOWMEMORY); } int SDL_tizen_app_init(int argc, char *argv[]) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL Tizen App initialize"); - if (tizen_appcore_initialized) - { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Already initialized!"); + SDL_Log( "SDL Tizen App initialize"); + if (tizen_appcore_initialized) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Already initialized!"); return 0; } tizen_appcore_initialized = 1; - if (argc < 1 || argv == NULL) - { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "APP_ERROR_INVALID_PARAMETER"); + if (argc < 1 || argv == NULL) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"APP_ERROR_INVALID_PARAMETER"); return 0; } diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 28b2b9f..ad73f70 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -346,6 +346,9 @@ struct SDL_VideoDevice SDL_bool (*vulkan_GetInstanceExtensions) (const char* driver, unsigned int* count, char** names); SDL_bool (*vulkan_CreateSurface) (_THIS, SDL_Window* window, SDL_vulkanInstance instance, SDL_vulkanSurface* surface); +#if __TIZEN__ + void (*GetWindowSize) (_THIS, SDL_Window * window, int *w, int *h); +#endif }; typedef struct VideoBootStrap diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index ecdbf6c..bb2819d 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1876,12 +1876,26 @@ void SDL_GetWindowSize(SDL_Window * window, int *w, int *h) { CHECK_WINDOW_MAGIC(window,); +#ifdef __TIZEN__ + if (_this->GetWindowSize) { + _this->GetWindowSize(_this, window, w, h); + } + else { + if (w) { + *w = window->w; + } + if (h) { + *h = window->h; + } + } +#else if (w) { *w = window->w; } if (h) { *h = window->h; } +#endif } void diff --git a/src/video/tizen/SDL_tizenevents.c b/src/video/tizen/SDL_tizenevents.c index cd28dfa..fd48476 100644 --- a/src/video/tizen/SDL_tizenevents.c +++ b/src/video/tizen/SDL_tizenevents.c @@ -43,7 +43,7 @@ Tizen_PumpEvents(_THIS) } Eina_Bool -__tizen_cb_event_keyup_change(void *data, int type, void *event) +_tizen_cb_event_keyup_change(void *data, int type, void *event) { if (!event) return ECORE_CALLBACK_PASS_ON; @@ -55,7 +55,7 @@ __tizen_cb_event_keyup_change(void *data, int type, void *event) } Eina_Bool -__tizen_cb_event_keydown_change(void *data, int type, void *event) +_tizen_cb_event_keydown_change(void *data, int type, void *event) { if (!event) return ECORE_CALLBACK_PASS_ON; diff --git a/src/video/tizen/SDL_tizenevents_c.h b/src/video/tizen/SDL_tizenevents_c.h index cb1205c..9f98f91 100644 --- a/src/video/tizen/SDL_tizenevents_c.h +++ b/src/video/tizen/SDL_tizenevents_c.h @@ -31,9 +31,9 @@ extern void Tizen_PumpEvents(_THIS); -extern Eina_Bool __tizen_cb_event_keyup_change(void *data, int type, void *event); +extern Eina_Bool _tizen_cb_event_keyup_change(void *data, int type, void *event); -extern Eina_Bool __tizen_cb_event_keydown_change(void *data, int type, void *event); +extern Eina_Bool _tizen_cb_event_keydown_change(void *data, int type, void *event); #endif /* _SDL_tizenevents_h */ diff --git a/src/video/tizen/SDL_tizenkeyboard.c b/src/video/tizen/SDL_tizenkeyboard.c index 8352111..b39e6a2 100644 --- a/src/video/tizen/SDL_tizenkeyboard.c +++ b/src/video/tizen/SDL_tizenkeyboard.c @@ -29,6 +29,7 @@ /* Tizen Keyboard */ +static TizenKeyboard tizen_keyboard; void _ecore_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, void *event_info) @@ -50,9 +51,12 @@ _ecore_imf_event_state_change_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, void Tizen_InitKeyboard(_THIS) { + //TODO : need the ref count + if (tizen_keyboard.imf_context) return; + ecore_imf_init(); - memset(&keyboard, 0, sizeof(keyboard)); + memset(&tizen_keyboard, 0, sizeof(tizen_keyboard)); const char *default_id = ecore_imf_context_default_id_get(); if (!default_id) @@ -61,29 +65,29 @@ void Tizen_InitKeyboard(_THIS) return; } - keyboard.imf_context = ecore_imf_context_add(default_id); + tizen_keyboard.imf_context = ecore_imf_context_add(default_id); SDL_Window *window = _this->windows; SDL_WindowData *wind = window->driverdata; - ecore_imf_context_client_window_set(keyboard.imf_context, (void*)wind->id); + ecore_imf_context_client_window_set(tizen_keyboard.imf_context, (void*)wind->id); - ecore_imf_context_event_callback_add(keyboard.imf_context, ECORE_IMF_CALLBACK_COMMIT , _ecore_imf_event_commit_cb, NULL); - ecore_imf_context_input_panel_event_callback_add (keyboard.imf_context, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _ecore_imf_event_state_change_cb, NULL); + ecore_imf_context_event_callback_add(tizen_keyboard.imf_context, ECORE_IMF_CALLBACK_COMMIT , _ecore_imf_event_commit_cb, NULL); + ecore_imf_context_input_panel_event_callback_add (tizen_keyboard.imf_context, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _ecore_imf_event_state_change_cb, NULL); - ecore_imf_context_cursor_position_set(keyboard.imf_context, 0); - ecore_imf_context_focus_out(keyboard.imf_context); - ecore_imf_context_input_panel_hide(keyboard.imf_context); + ecore_imf_context_cursor_position_set(tizen_keyboard.imf_context, 0); + ecore_imf_context_focus_out(tizen_keyboard.imf_context); + ecore_imf_context_input_panel_hide(tizen_keyboard.imf_context); } void Tizen_FiniKeyboard(void) { - if(keyboard.imf_context == NULL) + if(tizen_keyboard.imf_context == NULL) return; - ecore_imf_context_del(keyboard.imf_context); - keyboard.imf_context = NULL; + ecore_imf_context_del(tizen_keyboard.imf_context); + tizen_keyboard.imf_context = NULL; ecore_imf_shutdown(); } @@ -96,7 +100,7 @@ Tizen_StartTextInput(_THIS) return; } - if(keyboard.imf_context == NULL) + if(tizen_keyboard.imf_context == NULL) Tizen_InitKeyboard(_this); Tizen_ShowScreenKeyboard(_this, NULL); @@ -107,7 +111,7 @@ void Tizen_StopTextInput(_THIS) { if (!_this) return; - if (keyboard.imf_context) + if (tizen_keyboard.imf_context) { Tizen_HideScreenKeyboard(_this, _this->windows); } @@ -128,28 +132,28 @@ Tizen_HasScreenKeyboardSupport(_THIS) void Tizen_ShowScreenKeyboard(_THIS, SDL_Window * window) { - if (!keyboard.imf_context) + if (!tizen_keyboard.imf_context) return; - ecore_imf_context_focus_in(keyboard.imf_context); - ecore_imf_context_input_panel_show(keyboard.imf_context); + ecore_imf_context_focus_in(tizen_keyboard.imf_context); + ecore_imf_context_input_panel_show(tizen_keyboard.imf_context); } void Tizen_HideScreenKeyboard(_THIS, SDL_Window * window) { - if (!keyboard.imf_context) + if (!tizen_keyboard.imf_context) return; - ecore_imf_context_focus_out(keyboard.imf_context); - ecore_imf_context_input_panel_hide(keyboard.imf_context); + ecore_imf_context_focus_out(tizen_keyboard.imf_context); + ecore_imf_context_input_panel_hide(tizen_keyboard.imf_context); } SDL_bool Tizen_IsScreenKeyboardShown(_THIS, SDL_Window * window) { - if (!keyboard.imf_context) + if (!tizen_keyboard.imf_context) return SDL_FALSE; //EAPI Ecore_IMF_Input_Panel_State ecore_imf_context_input_panel_state_get (Ecore_IMF_Context *ctx) - return ecore_imf_context_input_panel_state_get(keyboard.imf_context); + return ecore_imf_context_input_panel_state_get(tizen_keyboard.imf_context); } diff --git a/src/video/tizen/SDL_tizenkeyboard.h b/src/video/tizen/SDL_tizenkeyboard.h index 8eb63ec..cb0b3c3 100644 --- a/src/video/tizen/SDL_tizenkeyboard.h +++ b/src/video/tizen/SDL_tizenkeyboard.h @@ -38,8 +38,6 @@ struct _TizenKeyboard Ecore_IMF_Context *imf_context; }; -static TizenKeyboard keyboard; - extern void Tizen_InitKeyboard(_THIS); extern void Tizen_FiniKeyboard(void); diff --git a/src/video/tizen/SDL_tizenmouse.c b/src/video/tizen/SDL_tizenmouse.c index 6aa46ad..65c364c 100755 --- a/src/video/tizen/SDL_tizenmouse.c +++ b/src/video/tizen/SDL_tizenmouse.c @@ -246,7 +246,7 @@ Tizen_FiniMouse(void) } Eina_Bool -__tizen_cb_event_mousedown_change(void *data, int type, void *event) +_tizen_cb_event_mousedown_change(void *data, int type, void *event) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); @@ -260,7 +260,7 @@ __tizen_cb_event_mousedown_change(void *data, int type, void *event) } Eina_Bool -__tizen_cb_event_mouseup_change(void *data, int type, void *event) +_tizen_cb_event_mouseup_change(void *data, int type, void *event) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); if (!event) return ECORE_CALLBACK_PASS_ON; @@ -273,7 +273,7 @@ __tizen_cb_event_mouseup_change(void *data, int type, void *event) } Eina_Bool -__tizen_cb_event_mousemove_change(void *data, int type, void *event) +_tizen_cb_event_mousemove_change(void *data, int type, void *event) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); diff --git a/src/video/tizen/SDL_tizenmouse.h b/src/video/tizen/SDL_tizenmouse.h index 6cd8e84..91a0a5e 100755 --- a/src/video/tizen/SDL_tizenmouse.h +++ b/src/video/tizen/SDL_tizenmouse.h @@ -31,8 +31,8 @@ extern void Tizen_InitMouse(void); extern void Tizen_FiniMouse(void); -extern Eina_Bool __tizen_cb_event_mouseup_change(void *data, int type, void *event); -extern Eina_Bool __tizen_cb_event_mousedown_change(void *data, int type, void *event); -extern Eina_Bool __tizen_cb_event_mousemove_change(void *data, int type, void *event); +extern Eina_Bool _tizen_cb_event_mouseup_change(void *data, int type, void *event); +extern Eina_Bool _tizen_cb_event_mousedown_change(void *data, int type, void *event); +extern Eina_Bool _tizen_cb_event_mousemove_change(void *data, int type, void *event); diff --git a/src/video/tizen/SDL_tizenopengles.c b/src/video/tizen/SDL_tizenopengles.c index 337eeae..26e72da 100644 --- a/src/video/tizen/SDL_tizenopengles.c +++ b/src/video/tizen/SDL_tizenopengles.c @@ -52,6 +52,12 @@ Tizen_GLES_CreateContext(_THIS, SDL_Window *window) void Tizen_GLES_SwapWindow(_THIS, SDL_Window *window) { + SDL_WindowData* wdata = (SDL_WindowData*)window->driverdata; + if (wdata->received_rotation == 1) { + ecore_wl_window_rotation_change_done_send(wdata->window); + wdata->received_rotation = 0; + } + SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface); } diff --git a/src/video/tizen/SDL_tizenvideo.c b/src/video/tizen/SDL_tizenvideo.c index df11641..e77503b 100644 --- a/src/video/tizen/SDL_tizenvideo.c +++ b/src/video/tizen/SDL_tizenvideo.c @@ -127,6 +127,7 @@ Tizen_CreateDevice(int devindex) device->DestroyWindow = Tizen_DestroyWindow; device->SetWindowHitTest = Tizen_SetWindowHitTest; device->GetWindowWMInfo = Tizen_GetWindowWMInfo; + device->SetWindowPosition = Tizen_SetWindowPosition; /* Text input */ device->StartTextInput = Tizen_StartTextInput; @@ -143,6 +144,7 @@ Tizen_CreateDevice(int devindex) device->vulkan_GetInstanceExtensions = Tizen_vulkan_GetInstanceExtensions; device->vulkan_CreateSurface = Tizen_vulkan_CreateSurface; #endif + device->GetWindowSize = Tizen_GetWindowSize; return device; } diff --git a/src/video/tizen/SDL_tizenvulkan.c b/src/video/tizen/SDL_tizenvulkan.c index 13b3c5e..f9e3948 100644 --- a/src/video/tizen/SDL_tizenvulkan.c +++ b/src/video/tizen/SDL_tizenvulkan.c @@ -57,8 +57,6 @@ Tizen_vulkan_GetInstanceExtensions(const char* driver, unsigned int* count, char { uint32_t instance_extension_count = 0; uint32_t enabled_extension_count = 0; - VkBool32 surfaceExtFound = 0; - VkBool32 platformSurfaceExtFound = 0; VkResult err; if (strcmp(driver, "tizen")) { diff --git a/src/video/tizen/SDL_tizenwindow.c b/src/video/tizen/SDL_tizenwindow.c index 20d8ab3..6618076 100644 --- a/src/video/tizen/SDL_tizenwindow.c +++ b/src/video/tizen/SDL_tizenwindow.c @@ -35,6 +35,7 @@ #include "SDL_tizenmouse.h" #include "SDL_tizenevents_c.h" #include "SDL_log.h" +#include "SDL_hints.h" #include "../../events/SDL_mouse_c.h" #include @@ -43,11 +44,6 @@ SDL_bool Tizen_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info) { SDL_WindowData *wmdata = (SDL_WindowData *)window->driverdata; - SDL_VideoData *video_data = (SDL_VideoData *)_this->driverdata; - -// info->info.tizen.display = video_data->display; -// info->info.tizen.surface = wmdata->surface; -// info->info.tizen.shell_surface = NULL; info->info.tizen.egl_display = NULL; info->info.tizen.egl_surface = NULL; #if SDL_VIDEO_OPENGL_EGL @@ -71,7 +67,6 @@ void Tizen_ShowWindow(_THIS, SDL_Window *window) { SDL_WindowData *wind = window->driverdata; - ecore_wl_window_show(wind->window); } @@ -82,15 +77,91 @@ Tizen_SetWindowFullscreen(_THIS, SDL_Window *window, /*DO NOTHING*/ } +static void +_tizen_window_orientaiton_hint_callback(void *userdata, const char *name, const char *oldValue, const char *newValue) +{ + char *p_str = NULL; + char orientation_type[4][20] = {"Portrait","LandscapeLeft","PortraitUpsideDown","LandscapeRight"}; + int checked[4] = {0,}; + int i; + unsigned int j = 0; + SDL_WindowData *wind = (SDL_WindowData*)userdata; + Ecore_Wl_Window *window = wind->window; + + 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)) { + return; + } + + for (i=0;i<4;i++) { + p_str = SDL_strstr(newValue, orientation_type[i]); + if (p_str) { + if (p_str == newValue) { + int rot = 0; + if (i == 0) rot = 0; + else if (i == 1) rot = 90; + else if (i == 2) rot = 180; + else if (i == 3) rot = 270; + wind->rotation = rot; + } + + if (i == 0) { + checked[j] = 0; + SDL_Log("SDL %s: avaiable rotation: 0", __FUNCTION__); + } + else if (i == 1) { + checked[j] = 90; + SDL_Log("SDL %s: avaiable rotation: 90", __FUNCTION__); + } + else if (i == 2) { + checked[j] = 180; + SDL_Log("SDL %s: avaiable rotation: 180", __FUNCTION__); + } + else if (i == 3) { + checked[j] = 270; + SDL_Log("SDL %s: avaiable rotation: 270", __FUNCTION__); + } + j++; + } + } + + if (j > 0) { + if (j == 1) { + ecore_wl_window_rotation_preferred_rotation_set(window,wind->rotation); + } + ecore_wl_window_rotation_available_rotations_set(window, (const int*)checked, j); + } +} + +static void +_tizen_window_orientation_add_hint(void *data) +{ + SDL_WindowData *wind = (SDL_WindowData*)data; + if (wind->rotation_supported == 0) { + return; + } + + SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, _tizen_window_orientaiton_hint_callback, data); +} + int Tizen_CreateWindow(_THIS, SDL_Window *window) { SDL_VideoData *data = _this->driverdata; SDL_WindowData *wind; + Ecore_Wl_Global *global; + Eina_Inlist *globals; wind = calloc(1, sizeof * wind); - if (!wind) + if (!wind) { return SDL_OutOfMemory(); + } window->driverdata = wind; @@ -107,11 +178,27 @@ Tizen_CreateWindow(_THIS, SDL_Window *window) window->y = 0; } + if (!(globals = ecore_wl_globals_get())) + { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get wayland globals"); + return -1; + } + wind->window = ecore_wl_window_new(NULL, window->x, window->y, window->w, window->h, ECORE_WL_WINDOW_BUFFER_TYPE_SHM); wind->surface = ecore_wl_window_surface_create(wind->window); + wind->rotation = 0; + wind->rotation_supported = 0; + wind->received_rotation = 0; ecore_wl_window_opaque_region_set(wind->window, window->x, window->y, window->w, window->h); + + if (window->flags & 0x00008000) + { + ecore_wl_window_input_region_set(wind->window, 0, 0, 0, 0); + ecore_wl_window_focus_skip_set(wind->window, EINA_TRUE); + } + #if SDL_VIDEO_OPENGL_EGL if (window->flags & SDL_WINDOW_OPENGL) { wind->egl_window = wl_egl_window_create(ecore_wl_window_surface_get(wind->window), window->w, window->h); @@ -119,7 +206,8 @@ Tizen_CreateWindow(_THIS, SDL_Window *window) /* Create the GLES window surface */ wind->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wind->egl_window); if (wind->egl_surface == EGL_NO_SURFACE) { - return SDL_SetError("failed to create a window surface"); + SDL_SetError("failed to create a window surface"); + return -1; } } #endif @@ -127,8 +215,7 @@ Tizen_CreateWindow(_THIS, SDL_Window *window) wind->id = ecore_wl_window_id_get(wind->window); eina_hash_add(data->windows, &wind->id, window); - if(keyboard.imf_context == NULL) - Tizen_InitKeyboard(_this); + Tizen_InitKeyboard(_this); SDL_SetMouseFocus(window); @@ -140,19 +227,87 @@ Tizen_CreateWindow(_THIS, SDL_Window *window) //ecore_wl_window_focus_skip_set(wind->window, EINA_TRUE); } + EINA_INLIST_FOREACH(globals, global) { + if (!strcmp(global->interface, "tizen_policy_ext")) { + wind->rotation_supported = 1; + SDL_Log("SDL can support rotation in this device!!!!!!!!!!!"); + break; + } + } + // Add orientaiton hint cb + _tizen_window_orientation_add_hint((void*)wind); return 0; } void -Tizen_SetWindowSize(_THIS, SDL_Window *window) +_tizen_setwindowsize(SDL_Window *window, int update_egl) { SDL_WindowData *wind = window->driverdata; + if (!wind->window) + { + return; + } + + // TODO : consider to rotation status. #if SDL_VIDEO_OPENGL_EGL - if (window->flags & SDL_WINDOW_OPENGL) { - ecore_wl_window_opaque_region_set(wind->window,window->x, window->y, window->w, window->h); - wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0); + if ((window->flags & SDL_WINDOW_OPENGL) && (update_egl == 1)) { + int aw, ah, dx = 0, dy = 0; + + if ((wind->rotation == 90) || (wind->rotation == 270)) + wl_egl_window_get_attached_size(wind->egl_window, &ah, &aw); + else + wl_egl_window_get_attached_size(wind->egl_window, &aw, &ah); + + SDL_Log("SDL %s:wl_egl_window_get_attached_size:rot(%i)%ix%i",__FUNCTION__,wind->rotation,aw,ah); + + // TODO : if window size is not FULL, we need the code about Non FullSize Window. + wl_egl_window_resize(wind->egl_window, window->w, window->h, dx, dy); } #endif + ecore_wl_window_update_size(wind->window, window->w, window->h); +} + +void +Tizen_SetWindowSize(_THIS, SDL_Window *window) +{ + _tizen_setwindowsize(window, 1); +} + +void +Tizen_GetWindowSize(_THIS, SDL_Window *window, int *w, int *h) +{ + SDL_WindowData *wind = window->driverdata; + int tmp_w, tmp_h; + if (!wind->window) { + return; + } + + tmp_w = window->w; + tmp_h = window->h; + if (wind->rotation == 90 || wind->rotation == 270) { + tmp_w = window->h; + tmp_h = window->w; + } + + if (w) { + *w = tmp_w; + } + if (h) { + *h = tmp_h; + } +} + + +void +Tizen_SetWindowPosition(_THIS, SDL_Window * window) +{ + SDL_WindowData *wind = window->driverdata; + if (!wind->window) { + return; + } + + // TODO : consider to rotation status. + ecore_wl_window_position_set(wind->window, window->x, window->y); } void @@ -177,7 +332,7 @@ Tizen_DestroyWindow(_THIS, SDL_Window *window) } static SDL_Window* -__tizen_find_window(_THIS, Ecore_Wl_Window *ewin) +_tizen_find_window(_THIS, Ecore_Wl_Window *ewin) { SDL_VideoData *data = _this->driverdata; int id; @@ -187,7 +342,7 @@ __tizen_find_window(_THIS, Ecore_Wl_Window *ewin) } static Eina_Bool -__tizen_cb_window_visibility_change(void *data, int type, void *event) +_tizen_cb_event_window_visibility_change(void *data, int type, void *event) { _THIS = data; Ecore_Wl_Event_Window_Visibility_Change *ev; @@ -196,13 +351,80 @@ __tizen_cb_window_visibility_change(void *data, int type, void *event) ev = event; ew = ecore_wl_window_find(ev->win); - window = __tizen_find_window(_this, ew); + window = _tizen_find_window(_this, ew); - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "visibility window: %p, ecore_wl_window: %p\n", window, ew); + SDL_Log( "visibility window: %p, ecore_wl_window: %p\n", window, ew); SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0); SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); + return ECORE_CALLBACK_PASS_ON; +} + +static Eina_Bool +_tizen_cb_window_configure(void *data, int type EINA_UNUSED, void *event) +{ + _THIS = data; + Ecore_Wl_Window *ew; + SDL_Window *window; + SDL_WindowData *wind; + Ecore_Wl_Event_Window_Configure *ev; + int nx = 0, ny = 0, nw = 0, nh = 0; + ev = event; + ew = ecore_wl_window_find(ev->win); + window = _tizen_find_window(_this, ew); + wind = window->driverdata; + + if (wind->rotation_supported == 0){ + return ECORE_CALLBACK_PASS_ON; + } + + 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; + + if ((window->x != nx) || (window->y != ny)) + ecore_wl_window_position_set(ew, nx, ny); + + if ((window->w != nw) || (window->h != nh)) { + window->w = nw; + window->h = nh; + + _tizen_setwindowsize(window, 0); + } + return ECORE_CALLBACK_PASS_ON; +} +static Eina_Bool +_tizen_cb_event_window_rotate(void *data, int type EINA_UNUSED, void *event) +{ + _THIS = data; + Ecore_Wl_Event_Window_Rotate *ev; + Ecore_Wl_Window *ew; + SDL_Window *window; + SDL_WindowData *wind; + + ev = event; + if (!ev) { + return ECORE_CALLBACK_PASS_ON; + } + + ew = ecore_wl_window_find(ev->win); + window = _tizen_find_window(_this, ew); + wind = window->driverdata; + + if (wind->rotation != ev->angle) { + /* 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); + } + wind->received_rotation = 1; return ECORE_CALLBACK_PASS_ON; } @@ -214,17 +436,21 @@ Tizen_InitWindow(_THIS) data->windows = eina_hash_int32_new(NULL); ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE, - __tizen_cb_window_visibility_change, _this); + _tizen_cb_event_window_visibility_change,_this); ecore_event_handler_add(ECORE_EVENT_KEY_UP, - __tizen_cb_event_keyup_change, NULL); + _tizen_cb_event_keyup_change,_this); ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, - __tizen_cb_event_keydown_change, NULL); + _tizen_cb_event_keydown_change,_this); ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, - __tizen_cb_event_mousedown_change, _this); + _tizen_cb_event_mousedown_change,_this); ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, - __tizen_cb_event_mouseup_change, _this); + _tizen_cb_event_mouseup_change,_this); ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, - __tizen_cb_event_mousemove_change, _this); + _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); return 0; } diff --git a/src/video/tizen/SDL_tizenwindow.h b/src/video/tizen/SDL_tizenwindow.h index 489137b..08d5baa 100644 --- a/src/video/tizen/SDL_tizenwindow.h +++ b/src/video/tizen/SDL_tizenwindow.h @@ -39,6 +39,9 @@ typedef struct { struct wl_shell_surface *shell_surface; struct wl_egl_window *egl_window; EGLSurface egl_surface; + int rotation; + int rotation_supported; + int received_rotation; } SDL_WindowData; extern void Tizen_ShowWindow(_THIS, SDL_Window *window); @@ -47,10 +50,12 @@ extern void Tizen_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_bool fullscreen); extern int Tizen_CreateWindow(_THIS, SDL_Window *window); extern void Tizen_SetWindowSize(_THIS, SDL_Window *window); +extern void Tizen_GetWindowSize(_THIS, SDL_Window *window, int *w, int *h); extern void Tizen_DestroyWindow(_THIS, SDL_Window *window); extern SDL_bool Tizen_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info); extern int Tizen_SetWindowHitTest(SDL_Window *window, SDL_bool enabled); +extern void Tizen_SetWindowPosition(_THIS, SDL_Window * window); extern int Tizen_InitWindow(_THIS); extern void Tizen_DeinitWindow(_THIS); diff --git a/src/video/wayland/SDL_waylandvulkan.c b/src/video/wayland/SDL_waylandvulkan.c index 3efd7ab..28c00e7 100644 --- a/src/video/wayland/SDL_waylandvulkan.c +++ b/src/video/wayland/SDL_waylandvulkan.c @@ -33,8 +33,6 @@ Wayland_vulkan_GetInstanceExtensions(const char* driver, unsigned int* count, ch { uint32_t instance_extension_count = 0; uint32_t enabled_extension_count = 0; - VkBool32 surfaceExtFound = 0; - VkBool32 platformSurfaceExtFound = 0; VkResult err; if (strcmp(driver, "wayland")) { -- 2.7.4