2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
23 #include "../../SDL_internal.h"
25 #if SDL_VIDEO_DRIVER_TIZEN
28 #include "SDL_hints.h"
29 #include "SDL_loadso.h"
31 #include "SDL_tizenvideo.h"
32 #include "SDL_tizentouch.h"
33 #include "SDL_tizenkeyboard.h"
34 #include "SDL_tizenmouse.h"
35 #include "SDL_tizenevents_c.h"
37 #include "SDL_tizenwindow.h"
38 #include "SDL_tizenopengles.h"
40 #include "../../events/SDL_mouse_c.h"
41 #include "../../joystick/tizen/SDL_sysjoystick_c.h"
43 #include "../SDL_egl_c.h"
44 #include "../SDL_sysvideo.h"
45 #include "../../events/SDL_windowevents_c.h"
47 #include <Ecore_Ipc.h>
48 #include <Ecore_Wl2.h>
53 Ecore_Ipc_Server *ipc = NULL;
55 #define IPC_HEAD(_type) \
56 Ecore_Ipc_Event_Client_##_type *e = event; \
57 if (ecore_ipc_client_server_get(e->client) != ipc) \
58 return ECORE_CALLBACK_PASS_ON
60 void _tizen_quickpanel_on(SDL_WindowData *wind)
62 SDL_Log("[SDL]Quick panel on");
63 ecore_wl2_window_indicator_state_set(wind->window, ECORE_WL2_INDICATOR_STATE_ON);
64 ecore_wl2_indicator_visible_type_set(wind->window, ECORE_WL2_INDICATOR_VISIBLE_TYPE_SHOWN);
67 void _tizen_quickpanel_off(SDL_WindowData *wind)
69 SDL_Log("[SDL]Quick panel off");
70 ecore_wl2_window_indicator_state_set(wind->window, ECORE_WL2_INDICATOR_STATE_OFF);
71 ecore_wl2_indicator_visible_type_set(wind->window, ECORE_WL2_INDICATOR_VISIBLE_TYPE_HIDDEN);
74 void Tizen_ExecuteIndicatorProcess(SDL_WindowData *wind)
76 SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
77 if(!videoData) return;
79 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Tizen Indicator is not supported");
83 Tizen_TerminateIndicatorProcess(SDL_WindowData *wind)
87 SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
88 if(videoData->indicator_on)
90 _tizen_ecore_ipc_client_send(OP_TERMINATE, 0, 0, 0);
91 _tizen_quickpanel_off(wind);
96 Tizen_chk_indicator(SDL_Window *window)
98 SDL_WindowData *wind = window->driverdata;
99 int screen_w, screen_h;
100 int rotation = wind->rotation % 360;
101 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
103 if(rotation % 180 == 0)
104 ecore_wl2_display_screen_size_get(wl2_display, &screen_w, &screen_h);
106 ecore_wl2_display_screen_size_get(wl2_display, &screen_h, &screen_w);
108 if(window->w == screen_w && window->h == screen_h && window->x == 0 && window->y == 0 && !(window->flags & SDL_WINDOW_BORDERLESS))
110 SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
111 if(!videoData->indicator_on)
113 wind->support_indicator = SDL_TRUE;
114 Tizen_ExecuteIndicatorProcess(wind);
119 wind->support_indicator = SDL_FALSE;
120 Tizen_TerminateIndicatorProcess(wind);
125 _tizen_ecore_ipc_client_send(int major, int minor, int ref, int ref_to)
127 Eina_List *ipc_clients = ecore_ipc_server_clients_get(ipc);
129 Ecore_Ipc_Client *cl;
130 EINA_LIST_FOREACH(ipc_clients, l, cl)
131 ecore_ipc_client_send(cl, major, minor, ref, ref_to, 0, NULL, 0);
135 _cb_client_add(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
139 SDL_Log("[SDL]_cb_client_add");
141 SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
142 videoData->indicator_on = SDL_TRUE;
144 SDL_Window * window = SDL_GetVideoDevice()->windows;
145 SDL_WindowData *wind = window->driverdata;
147 int window_w, window_h;
148 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
150 ecore_wl2_display_screen_size_get(wl2_display, &window_w, &window_h);
152 _tizen_ecore_ipc_client_send(OP_INDICATOR_SHOW, wind->rotation, wind->g_res_id, videoData->indicator_mode);
154 return ECORE_CALLBACK_DONE;
158 _cb_client_del(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
161 SDL_Log("[SDL]_cb_client_del");
162 Eina_List *ipc_clients = ecore_ipc_server_clients_get(ipc);
164 Ecore_Ipc_Client *cl;
165 EINA_LIST_FOREACH(ipc_clients, l, cl)
167 ecore_ipc_client_del(cl);
170 SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
171 videoData->indicator_on = SDL_FALSE;
173 return ECORE_CALLBACK_DONE;
177 _cb_client_data(void *data, int type EINA_UNUSED, void *event)
181 Ecore_Ipc_Event_Server_Data* epcEvent = (Ecore_Ipc_Event_Server_Data*)event;
182 SDL_Log("[SDL]_cb_client_data: %d -> %d", epcEvent->major, epcEvent->minor);
184 SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
185 SDL_Window * window = (SDL_Window*)eina_hash_find(videoData->windows, &videoData->indicator_parent_id);
188 SDL_Log("window is null");
189 return ECORE_CALLBACK_PASS_ON;
192 switch(epcEvent->major)
194 case OP_INDICATOR_INIT:
195 videoData->indicator_height = epcEvent->minor;
196 _tizen_quickpanel_on(window->driverdata);
198 case OP_INDICATOR_SHOW:
199 videoData->indicator_visible = SDL_TRUE;
201 case OP_INDICATOR_HIDE:
202 if(epcEvent->minor == 1)
204 _tizen_quickpanel_off(window->driverdata);
206 else if(epcEvent->minor == 2)
208 videoData->indicator_visible = SDL_FALSE;
212 videoData->indicator_on = SDL_FALSE;
213 videoData->indicator_visible = SDL_FALSE;
217 return ECORE_CALLBACK_DONE;
221 _tizen_init_ecore_ipc()
226 if(!ecore_ipc_init())
227 SDL_Log("[SDL]Fail ecore_ipc");
229 ipc = ecore_ipc_server_add(ECORE_IPC_LOCAL_USER, "sdl_indicator", 0, NULL);
232 ecore_ipc_shutdown();
234 ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, _cb_client_add, NULL);
235 ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, _cb_client_del, NULL);
236 ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA, _cb_client_data, NULL);
242 Tizen_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
244 SDL_WindowData *wmdata = (SDL_WindowData *)window->driverdata;
245 info->info.tizen.egl_display = NULL;
246 info->info.tizen.egl_surface = NULL;
247 #if SDL_VIDEO_OPENGL_EGL
250 info->info.tizen.egl_display = (void*)_this->egl_data->egl_display;
252 info->info.tizen.egl_surface = (void*)wmdata->egl_surface;
254 info->subsystem = SDL_SYSWM_TIZEN;
259 Tizen_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
261 return 0; /* just succeed, the real work is done elsewhere. */
265 Tizen_SetWindowTitle(_THIS, SDL_Window * window)
267 SDL_WindowData *wind = window->driverdata;
268 ecore_wl2_window_title_set(wind->window, window->title);
272 Tizen_ShowWindow(_THIS, SDL_Window *window)
274 SDL_WindowData *wind = window->driverdata;
275 ecore_wl2_window_show(wind->window);
280 Tizen_HideWindow(_THIS, SDL_Window *window)
282 SDL_WindowData *wind = window->driverdata;
283 ecore_wl2_window_hide(wind->window);
287 Tizen_RaiseWindow(_THIS, SDL_Window *window)
289 SDL_WindowData *wind = window->driverdata;
290 ecore_wl2_window_iconified_set(wind->window, SDL_FALSE);
291 ecore_wl2_window_raise(wind->window);
295 Tizen_SetWindowFullscreen(_THIS, SDL_Window *window,
296 SDL_VideoDisplay *_display, SDL_bool fullscreen)
298 SDL_WindowData *wind = window->driverdata;
301 int screen_w, screen_h;
302 int rotation = (wind->output_rotation + wind->rotation) % 360;
303 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
305 if(rotation == 90 || rotation == 270)
306 ecore_wl2_display_screen_size_get(wl2_display, &screen_h, &screen_w);
308 ecore_wl2_display_screen_size_get(wl2_display, &screen_w, &screen_h);
310 _tizen_set_window_size(window, screen_w, screen_h);
311 Tizen_SetWindowSize(_this, window);
313 window->fullscreen_mode.w = screen_w;
314 window->fullscreen_mode.h = screen_h;
318 _tizen_set_window_size(SDL_Window * window, int w, int h)
322 SDL_SetError("Invalid window");
326 SDL_VideoDevice *_this = SDL_GetVideoDevice();
328 SDL_SetError("Video subsystem has not been initialized");
332 if (window->magic != &_this->window_magic) {
337 SDL_InvalidParamError("w");
341 SDL_InvalidParamError("h");
345 /* Make sure we don't exceed any window size limits */
346 if (window->min_w && w < window->min_w)
350 if (window->max_w && w > window->max_w)
354 if (window->min_h && h < window->min_h)
358 if (window->max_h && h > window->max_h)
363 if(window->flags & SDL_WINDOW_FULLSCREEN)
365 window->fullscreen_mode.w = w;
366 window->fullscreen_mode.h = h;
369 window->windowed.w = w;
370 window->windowed.h = h;
377 _tizen_send_rotation_event(SDL_Window *window, unsigned int angle)
380 SDL_WindowData *wind;
381 wind = window->driverdata;
383 SDL_memset(&event, 0, sizeof(event));
384 event.type = SDL_ROTATEEVENT;
386 if (wind->support_pre_rotation)
387 event.user.data1 = (void*)0;
389 event.user.data1 = (void*)angle;
390 event.user.data2 = (void*)-1;
392 SDL_PushEvent(&event);
397 _tizen_get_rotation_idx(int rotation)
399 return ((rotation % 360) / 90);
403 _tizen_rotation_do(SDL_Window *window, SDL_WindowData* wind, int rotation)
405 int window_w, window_h;
406 if(wind->rotation == 0 || wind->rotation == 180)
407 ecore_wl2_window_geometry_get(wind->window, 0, 0, &window_w, &window_h);
409 ecore_wl2_window_geometry_get(wind->window, 0, 0, &window_h, &window_w);
411 _tizen_set_window_size(window, window_w, window_h);
413 #if SDL_VIDEO_OPENGL_EGL
414 if (window->flags & SDL_WINDOW_OPENGL)
416 if(wind->support_pre_rotation)
418 wl_egl_window_tizen_set_rotation(wind->egl_window, 360 - rotation);
419 wl_egl_window_tizen_set_buffer_transform(wind->egl_window, _tizen_get_rotation_idx(rotation));
420 wl_egl_window_tizen_set_window_transform(wind->egl_window, _tizen_get_rotation_idx(wind->rotation));
424 wl_egl_window_resize(wind->egl_window, window_w, window_h, 0, 0);
425 wl_egl_window_tizen_set_buffer_transform(wind->egl_window, _tizen_get_rotation_idx((360 - wind->rotation)));
426 wl_egl_window_tizen_set_window_transform(wind->egl_window, _tizen_get_rotation_idx(0));
430 _tizen_send_rotation_event(window, 0);
431 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
436 Tizen_rotate_update(SDL_Window *window)
438 SDL_WindowData *wind = window->driverdata;
442 if (ecore_wl2_window_ignore_output_transform_get(wind->window))
448 Ecore_Wl2_Output *output = ecore_wl2_window_output_find(wind->window);
449 screen_rotation = ecore_wl2_output_transform_get(output) * 90;
452 //Set Screen Rotation
453 wind->output_rotation = screen_rotation;
455 ecore_wl2_window_rotation_set(wind->window, wind->rotation);
457 int rotation = (wind->output_rotation + wind->rotation) % 360;
458 _tizen_rotation_do(window, wind, rotation);
462 Tizen_FindWindow(_THIS, Ecore_Wl2_Window *ewin)
464 SDL_VideoData *data = _this->driverdata;
467 id = ecore_wl2_window_id_get(ewin);
468 return (SDL_Window*)eina_hash_find(data->windows, &id);
472 _tizen_window_orientaiton_hint_callback(void *userdata, const char *name, const char *oldValue, const char *newValue)
475 char orientation_type[4][20] = {"Portrait","LandscapeLeft","PortraitUpsideDown","LandscapeRight"};
476 int checked[4] = {0,};
479 SDL_WindowData *wind = (SDL_WindowData*)userdata;
480 Ecore_Wl2_Window *window = wind->window;
482 if (wind->rotation_supported == 0)
485 SDL_assert(SDL_strncmp(name, SDL_HINT_ORIENTATIONS, SDL_strlen(SDL_HINT_ORIENTATIONS)) == 0);
487 if ((oldValue == NULL) && (newValue == NULL))
491 p_str = SDL_strstr(newValue, orientation_type[i]);
493 if (p_str == newValue) {
496 else if (i == 1) rot = 90;
497 else if (i == 2) rot = 180;
498 else if (i == 3) rot = 270;
499 wind->rotation = rot;
520 ecore_wl2_window_preferred_rotation_set(window, wind->rotation);
522 ecore_wl2_window_available_rotations_set(window, (const int*)checked, j);
526 SDL_Window *sdl_window = Tizen_FindWindow(SDL_GetVideoDevice(), window);
529 SDL_Log("Rotate error: sdl_window is null");
533 Tizen_rotate_update(sdl_window);
537 _tizen_window_orientation_add_hint(void *data)
539 SDL_WindowData *wind = (SDL_WindowData*)data;
540 if (wind->rotation_supported == 0)
543 SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, _tizen_window_orientaiton_hint_callback, data);
547 _tizen_cb_output_transform(void *data, int type EINA_UNUSED, void *event)
549 SDL_Window * window = SDL_GetVideoDevice()->windows;
550 SDL_WindowData *wind = window->driverdata;
552 if(!wind) return ECORE_CALLBACK_PASS_ON;
554 Ecore_Wl2_Event_Output_Transform *ev = event;
555 Ecore_Wl2_Output *output;
557 output = ecore_wl2_window_output_find(wind->window);
558 if (output != ev->output) return ECORE_CALLBACK_PASS_ON;
560 wind->received_rotation = TIZEN_ROTATION_RECEIVED_SCREEN_ROTATION;
563 return ECORE_CALLBACK_PASS_ON;
567 _tizen_cb_ignore_output_transform(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
569 SDL_Window * window = SDL_GetVideoDevice()->windows;
570 SDL_WindowData *wind = window->driverdata;
572 if(!wind) return ECORE_CALLBACK_PASS_ON;
574 wind->received_rotation = TIZEN_ROTATION_RECEIVED_SCREEN_ROTATION;
576 return ECORE_CALLBACK_PASS_ON;
580 _tizen_output_transform_register(SDL_WindowData *wind)
584 Ecore_Wl2_Output *output = ecore_wl2_window_output_find(wind->window);
585 wind->output_rotation = ecore_wl2_output_transform_get(output) * 90;
587 ecore_event_handler_add(ECORE_WL2_EVENT_OUTPUT_TRANSFORM,
588 _tizen_cb_output_transform, NULL);
589 ecore_event_handler_add(ECORE_WL2_EVENT_IGNORE_OUTPUT_TRANSFORM,
590 _tizen_cb_ignore_output_transform, NULL);
594 _tizen_indicator_opacity_hint_callback(void *userdata, const char *name, const char *oldValue, const char *newValue)
596 SDL_VideoData *data = (SDL_VideoData *)userdata;
598 if ((oldValue == NULL) && (newValue == NULL))
601 SDL_assert(SDL_strncmp(name, SDL_HINT_TIZEN_INDICATOR_OPACITY, SDL_strlen(SDL_HINT_TIZEN_INDICATOR_OPACITY)) == 0);
602 char indicator_type[4][20] = {"opaque","translucent","transparent","bg_transparent"};
603 for (int i=0;i<4;i++) {
604 if(SDL_strncmp(newValue, indicator_type[i], SDL_strlen(indicator_type[i])) == 0)
606 data->indicator_mode = i+1;
613 SDL_Tizen_GetSupportedAuxiliaryHintCount(SDL_Window *window)
615 SDL_WindowData *wind = NULL;
616 Ecore_Wl2_Window *ecore_window = NULL;
617 Eina_List* hints = NULL;
619 if (!window || !window->driverdata) {
623 wind = (SDL_WindowData *) window->driverdata;
624 ecore_window = wind->window;
626 SDL_Log("AddAuxiliaryHint: ecore_window is null");
630 hints = ecore_wl2_window_aux_hints_supported_get(ecore_window);
634 for (l = hints; l; l = eina_list_next(l)) {
642 SDL_Tizen_GetSupportedAuxiliaryHint(SDL_Window *window, unsigned int index)
644 SDL_WindowData *wind = NULL;
645 Ecore_Wl2_Window *ecore_window = NULL;
646 Eina_List* hints = NULL;
648 if (!window || !window->driverdata) {
652 wind = (SDL_WindowData *) window->driverdata;
653 ecore_window = wind->window;
655 SDL_Log("AddAuxiliaryHint: ecore_window is null");
659 hints = ecore_wl2_window_aux_hints_supported_get(ecore_window);
663 char* supported_hint = NULL;
665 for (l = hints, (supported_hint = (char*)(eina_list_data_get(l))); l; l = eina_list_next(l), (supported_hint = (char*)(eina_list_data_get(l)))) {
667 return supported_hint;
676 SDL_Tizen_GetNativeWindow(SDL_Window *window)
678 SDL_WindowData *wind = NULL;
679 Ecore_Wl2_Window *ecore_window = NULL;
681 if (!window || !window->driverdata) {
685 wind = (SDL_WindowData *) window->driverdata;
687 ecore_window = wind->window;
694 SDL_Tizen_AddAuxiliaryHint(SDL_Window *window, const char *hint, const char *value)
696 SDL_WindowData *wind = NULL;
697 Ecore_Wl2_Window *ecore_window = NULL;
698 Eina_List* hints = NULL;
699 SDL_bool supported = SDL_FALSE;
701 if (!window || !window->driverdata) {
705 wind = (SDL_WindowData *) window->driverdata;
706 ecore_window = wind->window;
708 SDL_Log("AddAuxiliaryHint: ecore_window is null");
712 hints = ecore_wl2_window_aux_hints_supported_get(ecore_window);
715 char* supported_hint = NULL;
716 for (l = hints, (supported_hint = (char*)(eina_list_data_get(l))); l; l = eina_list_next(l),
717 (supported_hint = (char*)(eina_list_data_get(l)))) {
718 if (!SDL_strncmp(supported_hint, hint, strlen(hint))) {
719 supported = SDL_TRUE;
727 SDL_Log("AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint);
731 unsigned int new_id = 1;
732 if ((wind->auxiliaryHints).auxHintHeader) {
733 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
734 AuxiliaryHint* nextAuxiliaryHint = auxiliaryHint->next;
735 while (auxiliaryHint) {
736 if (!SDL_strncmp(auxiliaryHint->hint, hint, strlen(hint))) {
737 auxiliaryHint->value = value;
738 SDL_Log("AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", auxiliaryHint->hint, auxiliaryHint->value, auxiliaryHint->id);
739 return auxiliaryHint->id;
741 auxiliaryHint = nextAuxiliaryHint;
742 nextAuxiliaryHint = NULL;
744 nextAuxiliaryHint = auxiliaryHint->next;
751 AuxiliaryHint* newAuxiliaryHint = (AuxiliaryHint *)SDL_calloc(1, sizeof(AuxiliaryHint));
752 if (!newAuxiliaryHint) {
753 SDL_Log("AddAuxiliaryHint: Fail calloc");
757 newAuxiliaryHint->id = new_id;
758 newAuxiliaryHint->hint = hint;
759 newAuxiliaryHint->value = value;
760 newAuxiliaryHint->next = NULL;
762 newAuxiliaryHint->next = (wind->auxiliaryHints).auxHintHeader;
765 (wind->auxiliaryHints).auxHintHeader = newAuxiliaryHint;
766 (wind->auxiliaryHints).size++;
767 ecore_wl2_window_aux_hint_add(ecore_window, (int)new_id, hint, value);
768 SDL_Log("AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint, value, new_id);
774 SDL_Tizen_RemoveAuxiliaryHint(SDL_Window *window, unsigned int id)
776 SDL_WindowData *wind = NULL;
777 Ecore_Wl2_Window *ecore_window = NULL;
779 if (!window || !window->driverdata) {
783 wind = (SDL_WindowData *) window->driverdata;
784 ecore_window = wind->window;
787 SDL_Log("RemoveAuxiliaryHint: ecore_window is null");
792 SDL_Log( "RemoveAuxiliaryHint: Invalid id [%d]\n", id );
796 if ((wind->auxiliaryHints).auxHintHeader) {
797 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
798 AuxiliaryHint* prevAuxiliaryHint = NULL;
799 AuxiliaryHint* nextAuxiliaryHint = auxiliaryHint->next;
800 while (auxiliaryHint) {
801 if (auxiliaryHint->id == id) {
802 SDL_Log("RemoveAuxiliaryHint: id = %d, hint = %s\n", id, auxiliaryHint->hint);
803 ecore_wl2_window_aux_hint_del(ecore_window, (int)id);
804 if (auxiliaryHint == (wind->auxiliaryHints).auxHintHeader) {
805 (wind->auxiliaryHints).auxHintHeader = auxiliaryHint->next;
807 prevAuxiliaryHint->next = nextAuxiliaryHint;
809 SDL_free(auxiliaryHint);
810 (wind->auxiliaryHints).size--;
813 prevAuxiliaryHint = auxiliaryHint;
814 auxiliaryHint = nextAuxiliaryHint;
815 nextAuxiliaryHint = NULL;
817 nextAuxiliaryHint = auxiliaryHint->next;
825 SDL_Tizen_SetAuxiliaryHint(SDL_Window *window, unsigned int id, const char *value)
827 SDL_WindowData *wind = NULL;
828 Ecore_Wl2_Window *ecore_window = NULL;
830 if (!window || !window->driverdata) {
834 wind = (SDL_WindowData *) window->driverdata;
835 ecore_window = wind->window;
842 SDL_Log( "RemoveAuxiliaryHint: Invalid id [%d]\n", id );
846 if ((wind->auxiliaryHints).auxHintHeader) {
847 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
848 AuxiliaryHint* nextAuxiliaryHint = auxiliaryHint->next;
849 while (auxiliaryHint) {
850 if (auxiliaryHint->id == id) {
851 ecore_wl2_window_aux_hint_change(ecore_window, (int)id, value);
852 auxiliaryHint->value = value;
853 SDL_Log("SetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, auxiliaryHint->hint, auxiliaryHint->value);
856 auxiliaryHint = nextAuxiliaryHint;
857 nextAuxiliaryHint = NULL;
859 nextAuxiliaryHint = auxiliaryHint->next;
867 SDL_Tizen_GetAuxiliaryHintValue(SDL_Window *window, unsigned int id)
869 SDL_WindowData *wind = NULL;
870 if (!window || !window->driverdata) {
874 wind = (SDL_WindowData *) window->driverdata;
876 SDL_Log( "GetAuxiliaryHintValue: Invalid id [%d]\n", id );
880 if ((wind->auxiliaryHints).auxHintHeader) {
881 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
882 while (auxiliaryHint) {
883 if (auxiliaryHint->id == id) {
884 SDL_Log("GetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, auxiliaryHint->hint, auxiliaryHint->value);
885 return auxiliaryHint->value;
887 auxiliaryHint = auxiliaryHint->next;
894 SDL_Tizen_GetAuxiliaryHintId(SDL_Window *window, const char *hint)
896 SDL_WindowData *wind = NULL;
897 if (!window || !window->driverdata) {
901 wind = (SDL_WindowData *) window->driverdata;
903 if (hint == NULL || (wind->auxiliaryHints).size <= 0) {
904 SDL_Log( "GetAuxiliaryHintId: auxiliaryHints size is 0]\n");
908 if ((wind->auxiliaryHints).auxHintHeader) {
909 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
910 for (unsigned int i = 0; i < (wind->auxiliaryHints).size; i++) {
911 if (auxiliaryHint->hint == hint) {
912 SDL_Log("GetAuxiliaryHintId: hint = %s, id = %d\n", hint, auxiliaryHint->id);
913 return auxiliaryHint->id;
915 auxiliaryHint = auxiliaryHint->next;
918 SDL_Log("GetAuxiliaryHintId: Invalid hint! [%s]\n", hint);
924 SDL_Tizen_GetWindowAcceptFocus(SDL_Window * window)
926 SDL_WindowData *data = NULL;
928 if (!window || !window->driverdata) {
932 data = (SDL_WindowData *) window->driverdata;
937 return !ecore_wl2_window_focus_skip_get(data->window);
941 SDL_Tizen_SetWindowAcceptFocus(SDL_Window * window, SDL_bool accept)
943 SDL_WindowData *data = NULL;
945 if (!window || !window->driverdata) {
949 data = (SDL_WindowData *) window->driverdata;
954 ecore_wl2_window_focus_skip_set(data->window, !accept);
959 Tizen_CreateWindow(_THIS, SDL_Window *window)
961 SDL_VideoData *data = _this->driverdata;
962 SDL_WindowData *wind;
963 Ecore_Wl2_Global *global;
964 Eina_Iterator *globals;
965 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
966 Ecore_Wl2_Window *parent_wl2_window = NULL;
968 wind = calloc(1, sizeof * wind);
970 return SDL_OutOfMemory();
972 (wind->auxiliaryHints).size = 0;
973 (wind->auxiliaryHints).auxHintHeader = NULL;
974 window->driverdata = wind;
975 window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
977 #if SDL_VIDEO_OPENGL_EGL
978 if (window->flags & SDL_WINDOW_OPENGL) {
979 SDL_GL_LoadLibrary(NULL);
984 if (window->flags & SDL_WINDOW_VULKAN) {
985 if (!_this->Vulkan_GetInstanceExtensions) {
986 SDL_SetError("No Vulkan support in video driver");
989 if (_this->Vulkan_LoadLibrary(_this, NULL) < 0) {
990 SDL_SetError("Fail to load Vulkan Library");
995 if (window->x == SDL_WINDOWPOS_UNDEFINED) {
998 if (window->y == SDL_WINDOWPOS_UNDEFINED) {
1002 if (!(globals = ecore_wl2_display_globals_get(wl2_display)))
1004 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to get wayland globals");
1010 parent_wl2_window = ((SDL_WindowData *)(window->next->driverdata))->window;
1012 wind->window = ecore_wl2_window_new(wl2_display, parent_wl2_window,
1013 window->x, window->y, window->w, window->h);
1014 if (!wind->window) {
1015 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to create wayland window");
1017 eina_iterator_free(globals);
1021 ecore_wl2_window_position_set(wind->window, window->x, window->y);
1022 _tizen_output_transform_register(wind);
1024 wind->wl2_surface = ecore_wl2_surface_create(wind->window, EINA_FALSE);
1025 if (!wind->wl2_surface) {
1026 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to create wayland window surface");
1030 wind->surface = ecore_wl2_window_surface_get(wind->window);
1031 if (!wind->surface) {
1032 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to create wayland window surface");
1034 eina_iterator_free(globals);
1039 ecore_wl2_window_type_set(wind->window, ECORE_WL2_WINDOW_TYPE_UTILITY);
1042 wind->rotation_supported = 0;
1043 wind->received_rotation = TIZEN_ROTATION_RECEIVED_NONE;
1045 #if SDL_VIDEO_OPENGL_EGL
1046 if (window->flags & SDL_WINDOW_OPENGL) {
1048 if(wind->output_rotation == 90 || wind->output_rotation == 270)
1049 wind->egl_window = wl_egl_window_create(wind->surface, window->h, window->w);
1051 wind->egl_window = wl_egl_window_create(wind->surface, window->w, window->h);
1053 /* Create the GLES window surface */
1054 wind->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wind->egl_window);
1055 if (wind->egl_surface == EGL_NO_SURFACE) {
1056 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "failed to create a window surface");
1058 eina_iterator_free(globals);
1063 if (!_this->gl_config.alpha_size) {
1064 ecore_wl2_window_opaque_region_set(wind->window, window->x, window->y, window->w, window->h);
1067 wl_surface_set_opaque_region(wind->surface, NULL);
1070 //Support PreRotation
1071 wind->support_pre_rotation = 0;
1072 if (wl_egl_window_tizen_get_capabilities(wind->egl_window) == WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_SUPPORTED ) {
1073 wind->support_pre_rotation = 1;
1077 wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
1084 wind->id = ecore_wl2_window_id_get(wind->window);
1085 eina_hash_add(data->windows, &wind->id, window);
1087 Tizen_InitKeyboard(_this);
1088 SDL_SetMouseFocus(window);
1090 EINA_ITERATOR_FOREACH(globals, global) {
1091 if (!strcmp(global->interface, "tizen_policy_ext")) {
1092 wind->rotation_supported = 1;
1096 eina_iterator_free(globals);
1097 // Add orientaiton hint cb
1098 _tizen_window_orientation_add_hint((void*)wind);
1099 SDL_AddHintCallback(SDL_HINT_TIZEN_INDICATOR_OPACITY, _tizen_indicator_opacity_hint_callback, data);
1101 Tizen_rotate_update(window);
1107 Tizen_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
1111 SDL_WindowData *wind = window->driverdata;
1112 wind->support_indicator = SDL_FALSE;
1113 Tizen_TerminateIndicatorProcess(window->driverdata);
1118 Tizen_SetWindowSize(_THIS, SDL_Window *window)
1120 SDL_WindowData *wind = window->driverdata;
1121 if (!wind->egl_window)
1124 // TODO : consider to rotation status.
1125 #if SDL_VIDEO_OPENGL_EGL
1126 if (window->flags & SDL_WINDOW_OPENGL)
1128 int rotation = (wind->output_rotation + wind->rotation) % 360;
1129 if(rotation == 90 || rotation == 270)
1131 ecore_wl2_window_geometry_set(wind->window, window->y, window->x, window->h, window->w);
1132 wl_egl_window_resize(wind->egl_window, window->h, window->w, 0, 0);
1136 ecore_wl2_window_geometry_set(wind->window, window->x, window->y, window->w, window->h);
1137 wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
1140 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
1145 Tizen_GetWindowSize(_THIS, SDL_Window *window, int *w, int *h)
1147 SDL_WindowData *wind = window->driverdata;
1148 if (!wind->window) {
1152 if (w) *w = window->w;
1153 if (h) *h = window->h;
1157 Tizen_SetWindowPosition(_THIS, SDL_Window * window)
1159 SDL_WindowData *wind = window->driverdata;
1160 if (!wind->window) {
1164 // TODO : consider to rotation status.
1165 ecore_wl2_window_position_set(wind->window, window->x, window->y);
1169 Tizen_DestroyWindow(_THIS, SDL_Window *window)
1171 SDL_VideoData *data = _this->driverdata;
1172 SDL_WindowData *wind = window->driverdata;
1175 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
1176 if (auxiliaryHint) {
1177 AuxiliaryHint* nextAuxiliaryHints = auxiliaryHint->next;
1178 while (auxiliaryHint) {
1179 SDL_free(auxiliaryHint);
1180 auxiliaryHint = nextAuxiliaryHints;
1181 nextAuxiliaryHints = NULL;
1182 if (auxiliaryHint) {
1183 nextAuxiliaryHints = auxiliaryHint->next;
1187 eina_hash_del(data->windows, &wind->id, window);
1188 #if SDL_VIDEO_OPENGL_EGL
1189 if (window->flags & SDL_WINDOW_OPENGL) {
1190 SDL_EGL_DestroySurface(_this, wind->egl_surface);
1191 wl_egl_window_destroy(wind->egl_window);
1194 ecore_wl2_window_free(wind->window);
1198 window->driverdata = NULL;
1202 Tizen_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
1204 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
1205 if (opacity < 1.0f) {
1206 ecore_wl2_window_alpha_set(data->window, true);
1208 ecore_wl2_window_alpha_set(data->window, false);
1214 _tizen_cb_event_window_visibility_change(void *data, int type, void *event)
1217 Ecore_Wl2_Event_Window_Visibility_Change *ev;
1218 Ecore_Wl2_Window *ew;
1221 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
1225 ew = ecore_wl2_display_window_find(wl2_display, ev->win);
1226 window = Tizen_FindWindow(_this, ew);
1228 return ECORE_CALLBACK_PASS_ON;
1231 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0);
1232 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
1233 return ECORE_CALLBACK_PASS_ON;
1237 _tizen_cb_window_configure(void *data, int type EINA_UNUSED, void *event)
1240 Ecore_Wl2_Window *ew;
1242 SDL_WindowData *wind;
1243 Ecore_Wl2_Event_Window_Configure *ev;
1245 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
1248 ew = ecore_wl2_display_window_find(wl2_display, ev->win);
1249 window = Tizen_FindWindow(_this, ew);
1251 return ECORE_CALLBACK_PASS_ON;
1254 wind = window->driverdata;
1256 return ECORE_CALLBACK_PASS_ON;
1259 if (wind->rotation_supported == 0){
1260 return ECORE_CALLBACK_PASS_ON;
1263 return ECORE_CALLBACK_PASS_ON;
1267 _tizen_cb_event_window_rotate(void *data, int type EINA_UNUSED, void *event)
1270 Ecore_Wl2_Event_Window_Rotation *ev;
1271 Ecore_Wl2_Window *ew;
1273 SDL_WindowData *wind;
1275 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
1279 return ECORE_CALLBACK_PASS_ON;
1282 ew = ecore_wl2_display_window_find(wl2_display, ev->win);
1283 window = Tizen_FindWindow(_this, ew);
1285 return ECORE_CALLBACK_PASS_ON;
1288 wind = window->driverdata;
1290 return ECORE_CALLBACK_PASS_ON;
1293 /* set ecore_wl2 window rotation */
1294 wind->rotation = ev->angle;
1295 wind->received_rotation = TIZEN_ROTATION_RECEIVED_WINDOW_ROATION;
1297 return ECORE_CALLBACK_PASS_ON;
1300 static Eina_Bool _tizen_cb_event_window_show(void *data, int type, void *event)
1302 Ecore_Wl2_Event_Window_Show *e;
1303 uint32_t g_res_id = 0;
1307 g_res_id = e->data[0];
1311 SDL_VideoData *this = SDL_GetVideoDevice()->driverdata;
1312 SDL_Window * window = (SDL_Window*)eina_hash_find(this->windows, &e->win);
1315 SDL_Log("window is null");
1316 return ECORE_CALLBACK_PASS_ON;
1318 SDL_WindowData *wind = window->driverdata;
1321 SDL_Log("window->driverdata is null");
1322 return ECORE_CALLBACK_PASS_ON;
1324 wind->g_res_id = g_res_id;
1325 SDL_Log("[SDL] SDL Window Resource ID %d", g_res_id);
1328 return ECORE_CALLBACK_PASS_ON;
1332 Tizen_InitWindow(_THIS)
1334 SDL_VideoData *data = _this->driverdata;
1336 data->windows = eina_hash_int32_new(NULL);
1338 ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE,
1339 _tizen_cb_event_window_visibility_change,_this);
1340 ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_ROTATE,
1341 _tizen_cb_event_window_rotate,_this);
1342 ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE,
1343 _tizen_cb_window_configure,_this);
1344 ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_SHOW,
1345 _tizen_cb_event_window_show, _this);
1347 ecore_event_handler_add(ECORE_EVENT_KEY_UP,
1348 _tizen_cb_event_keyup_change,_this);
1349 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
1350 _tizen_cb_event_keydown_change,_this);
1352 ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
1353 _tizen_cb_event_mousedown_change,_this);
1354 ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
1355 _tizen_cb_event_mouseup_change,_this);
1356 ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE,
1357 _tizen_cb_event_mousemove_change,_this);
1358 ecore_event_handler_add(ECORE_EVENT_MOUSE_IN,
1359 _tizen_cb_event_mouse_in,_this);
1360 ecore_event_handler_add(ECORE_EVENT_MOUSE_OUT,
1361 _tizen_cb_event_mouse_out,_this);
1363 ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN,
1364 _tizen_cb_event_focus_in,_this);
1365 ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT,
1366 _tizen_cb_event_focus_out,_this);
1368 ecore_event_handler_add(ECORE_EVENT_JOYSTICK,
1369 _tizen_cb_event_joystick_change,_this);
1375 Tizen_DeinitWindow(_THIS)
1377 SDL_VideoData *data = _this->driverdata;
1379 eina_hash_free(data->windows);
1381 #endif /* SDL_VIDEO_DRIVER_TIZEN */
1383 /* vi: set ts=4 sw=4 expandtab: */