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;
54 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
56 #define IPC_HEAD(_type) \
57 Ecore_Ipc_Event_Client_##_type *e = event; \
58 if (ecore_ipc_client_server_get(e->client) != ipc) \
59 return ECORE_CALLBACK_PASS_ON
61 void _tizen_quickpanel_on(SDL_WindowData *wind)
63 SDL_Log("[SDL]Quick panel on");
64 ecore_wl2_window_indicator_state_set(wind->window, ECORE_WL2_INDICATOR_STATE_ON);
65 ecore_wl2_indicator_visible_type_set(wind->window, ECORE_WL2_INDICATOR_VISIBLE_TYPE_SHOWN);
68 void _tizen_quickpanel_off(SDL_WindowData *wind)
70 SDL_Log("[SDL]Quick panel off");
71 ecore_wl2_window_indicator_state_set(wind->window, ECORE_WL2_INDICATOR_STATE_OFF);
72 ecore_wl2_indicator_visible_type_set(wind->window, ECORE_WL2_INDICATOR_VISIBLE_TYPE_HIDDEN);
75 void Tizen_ExecuteIndicatorProcess(SDL_WindowData *wind)
77 SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
78 if(!videoData) return;
80 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Tizen Indicator is not supported");
84 Tizen_TerminateIndicatorProcess(SDL_WindowData *wind)
88 SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
89 if(videoData->indicator_on)
91 _tizen_ecore_ipc_client_send(OP_TERMINATE, 0, 0, 0);
92 _tizen_quickpanel_off(wind);
97 Tizen_chk_indicator(SDL_Window *window)
99 SDL_WindowData *wind = window->driverdata;
100 int screen_w, screen_h;
101 int rotation = wind->rotation % 360;
102 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
104 if(rotation % 180 == 0)
105 ecore_wl2_display_screen_size_get(wl2_display, &screen_w, &screen_h);
107 ecore_wl2_display_screen_size_get(wl2_display, &screen_h, &screen_w);
109 if(window->w == screen_w && window->h == screen_h && window->x == 0 && window->y == 0 && !(window->flags & SDL_WINDOW_BORDERLESS))
111 SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
112 if(!videoData->indicator_on)
114 wind->support_indicator = SDL_TRUE;
115 Tizen_ExecuteIndicatorProcess(wind);
120 wind->support_indicator = SDL_FALSE;
121 Tizen_TerminateIndicatorProcess(wind);
126 _tizen_ecore_ipc_client_send(int major, int minor, int ref, int ref_to)
128 Eina_List *ipc_clients = ecore_ipc_server_clients_get(ipc);
130 Ecore_Ipc_Client *cl;
131 EINA_LIST_FOREACH(ipc_clients, l, cl)
132 ecore_ipc_client_send(cl, major, minor, ref, ref_to, 0, NULL, 0);
136 _cb_client_add(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
140 SDL_Log("[SDL]_cb_client_add");
142 SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
143 videoData->indicator_on = SDL_TRUE;
145 SDL_Window * window = SDL_GetVideoDevice()->windows;
146 SDL_WindowData *wind = window->driverdata;
148 int window_w, window_h;
149 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
151 ecore_wl2_display_screen_size_get(wl2_display, &window_w, &window_h);
153 _tizen_ecore_ipc_client_send(OP_INDICATOR_SHOW, wind->rotation, wind->g_res_id, videoData->indicator_mode);
155 return ECORE_CALLBACK_DONE;
159 _cb_client_del(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
162 SDL_Log("[SDL]_cb_client_del");
163 Eina_List *ipc_clients = ecore_ipc_server_clients_get(ipc);
165 Ecore_Ipc_Client *cl;
166 EINA_LIST_FOREACH(ipc_clients, l, cl)
168 ecore_ipc_client_del(cl);
171 SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
172 videoData->indicator_on = SDL_FALSE;
174 return ECORE_CALLBACK_DONE;
178 _cb_client_data(void *data, int type EINA_UNUSED, void *event)
182 Ecore_Ipc_Event_Server_Data* epcEvent = (Ecore_Ipc_Event_Server_Data*)event;
183 SDL_Log("[SDL]_cb_client_data: %d -> %d", epcEvent->major, epcEvent->minor);
185 SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
186 SDL_Window * window = (SDL_Window*)eina_hash_find(videoData->windows, &videoData->indicator_parent_id);
189 SDL_Log("window is null");
190 return ECORE_CALLBACK_PASS_ON;
193 switch(epcEvent->major)
195 case OP_INDICATOR_INIT:
196 videoData->indicator_height = epcEvent->minor;
197 _tizen_quickpanel_on(window->driverdata);
199 case OP_INDICATOR_SHOW:
200 videoData->indicator_visible = SDL_TRUE;
202 case OP_INDICATOR_HIDE:
203 if(epcEvent->minor == 1)
205 _tizen_quickpanel_off(window->driverdata);
207 else if(epcEvent->minor == 2)
209 videoData->indicator_visible = SDL_FALSE;
213 videoData->indicator_on = SDL_FALSE;
214 videoData->indicator_visible = SDL_FALSE;
218 return ECORE_CALLBACK_DONE;
222 _tizen_init_ecore_ipc()
227 if(!ecore_ipc_init())
228 SDL_Log("[SDL]Fail ecore_ipc");
230 ipc = ecore_ipc_server_add(ECORE_IPC_LOCAL_USER, "sdl_indicator", 0, NULL);
233 ecore_ipc_shutdown();
235 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, _cb_client_add, NULL));
236 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, _cb_client_del, NULL));
237 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA, _cb_client_data, NULL));
243 Tizen_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
245 SDL_WindowData *wmdata = (SDL_WindowData *)window->driverdata;
246 info->info.tizen.egl_display = NULL;
247 info->info.tizen.egl_surface = NULL;
248 #if SDL_VIDEO_OPENGL_EGL
251 info->info.tizen.egl_display = (void*)_this->egl_data->egl_display;
253 info->info.tizen.egl_surface = (void*)wmdata->egl_surface;
255 info->subsystem = SDL_SYSWM_TIZEN;
260 Tizen_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
262 return 0; /* just succeed, the real work is done elsewhere. */
266 Tizen_SetWindowTitle(_THIS, SDL_Window * window)
268 SDL_WindowData *wind = window->driverdata;
269 ecore_wl2_window_title_set(wind->window, window->title);
273 Tizen_ShowWindow(_THIS, SDL_Window *window)
275 SDL_WindowData *wind = window->driverdata;
276 ecore_wl2_window_show(wind->window);
281 Tizen_HideWindow(_THIS, SDL_Window *window)
283 SDL_WindowData *wind = window->driverdata;
284 ecore_wl2_window_hide(wind->window);
288 Tizen_RaiseWindow(_THIS, SDL_Window *window)
290 SDL_WindowData *wind = window->driverdata;
291 ecore_wl2_window_iconified_set(wind->window, SDL_FALSE);
292 ecore_wl2_window_raise(wind->window);
296 Tizen_SetWindowFullscreen(_THIS, SDL_Window *window,
297 SDL_VideoDisplay *_display, SDL_bool fullscreen)
299 SDL_WindowData *wind = window->driverdata;
302 int screen_w, screen_h;
303 int rotation = (wind->output_rotation + wind->rotation) % 360;
304 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
306 if(rotation == 90 || rotation == 270)
307 ecore_wl2_display_screen_size_get(wl2_display, &screen_h, &screen_w);
309 ecore_wl2_display_screen_size_get(wl2_display, &screen_w, &screen_h);
311 _tizen_set_window_size(window, screen_w, screen_h);
312 Tizen_SetWindowSize(_this, window);
314 window->fullscreen_mode.w = screen_w;
315 window->fullscreen_mode.h = screen_h;
319 _tizen_set_window_size(SDL_Window * window, int w, int h)
323 SDL_SetError("Invalid window");
327 SDL_VideoDevice *_this = SDL_GetVideoDevice();
329 SDL_SetError("Video subsystem has not been initialized");
333 if (window->magic != &_this->window_magic) {
338 SDL_InvalidParamError("w");
342 SDL_InvalidParamError("h");
346 /* Make sure we don't exceed any window size limits */
347 if (window->min_w && w < window->min_w)
351 if (window->max_w && w > window->max_w)
355 if (window->min_h && h < window->min_h)
359 if (window->max_h && h > window->max_h)
364 if(window->flags & SDL_WINDOW_FULLSCREEN)
366 window->fullscreen_mode.w = w;
367 window->fullscreen_mode.h = h;
370 window->windowed.w = w;
371 window->windowed.h = h;
378 _tizen_send_rotation_event(SDL_Window *window, unsigned int angle)
381 SDL_WindowData *wind;
382 wind = window->driverdata;
384 SDL_memset(&event, 0, sizeof(event));
385 event.type = SDL_ROTATEEVENT;
387 if (wind->support_pre_rotation)
388 event.user.data1 = (void*)0;
390 event.user.data1 = (void*)angle;
391 event.user.data2 = (void*)-1;
393 SDL_PushEvent(&event);
398 _tizen_get_rotation_idx(int rotation)
400 return ((rotation % 360) / 90);
404 _tizen_rotation_do(SDL_Window *window, SDL_WindowData* wind, int rotation)
406 int window_w, window_h;
407 if(wind->rotation == 0 || wind->rotation == 180)
408 ecore_wl2_window_geometry_get(wind->window, 0, 0, &window_w, &window_h);
410 ecore_wl2_window_geometry_get(wind->window, 0, 0, &window_h, &window_w);
412 _tizen_set_window_size(window, window_w, window_h);
414 #if SDL_VIDEO_OPENGL_EGL
415 if (window->flags & SDL_WINDOW_OPENGL)
417 if(wind->support_pre_rotation)
419 wl_egl_window_tizen_set_rotation(wind->egl_window, 360 - rotation);
420 wl_egl_window_tizen_set_buffer_transform(wind->egl_window, _tizen_get_rotation_idx(rotation));
421 wl_egl_window_tizen_set_window_transform(wind->egl_window, _tizen_get_rotation_idx(wind->rotation));
425 wl_egl_window_resize(wind->egl_window, window_w, window_h, 0, 0);
426 wl_egl_window_tizen_set_buffer_transform(wind->egl_window, _tizen_get_rotation_idx((360 - wind->rotation)));
427 wl_egl_window_tizen_set_window_transform(wind->egl_window, _tizen_get_rotation_idx(0));
431 _tizen_send_rotation_event(window, 0);
432 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
437 Tizen_rotate_update(SDL_Window *window)
439 SDL_WindowData *wind = window->driverdata;
443 if (ecore_wl2_window_ignore_output_transform_get(wind->window))
449 Ecore_Wl2_Output *output = ecore_wl2_window_output_find(wind->window);
450 screen_rotation = ecore_wl2_output_transform_get(output) * 90;
453 //Set Screen Rotation
454 wind->output_rotation = screen_rotation;
456 ecore_wl2_window_rotation_set(wind->window, wind->rotation);
458 int rotation = (wind->output_rotation + wind->rotation) % 360;
459 _tizen_rotation_do(window, wind, rotation);
463 Tizen_FindWindow(_THIS, Ecore_Wl2_Window *ewin)
465 SDL_VideoData *data = _this->driverdata;
468 id = ecore_wl2_window_id_get(ewin);
469 return (SDL_Window*)eina_hash_find(data->windows, &id);
473 _tizen_window_orientaiton_hint_callback(void *userdata, const char *name, const char *oldValue, const char *newValue)
476 char orientation_type[4][20] = {"Portrait","LandscapeLeft","PortraitUpsideDown","LandscapeRight"};
477 int checked[4] = {0,};
480 SDL_WindowData *wind = (SDL_WindowData*)userdata;
481 Ecore_Wl2_Window *window = wind->window;
483 if (wind->rotation_supported == 0)
486 SDL_assert(SDL_strncmp(name, SDL_HINT_ORIENTATIONS, SDL_strlen(SDL_HINT_ORIENTATIONS)) == 0);
488 if ((oldValue == NULL) && (newValue == NULL))
492 p_str = SDL_strstr(newValue, orientation_type[i]);
494 if (p_str == newValue) {
497 else if (i == 1) rot = 90;
498 else if (i == 2) rot = 180;
499 else if (i == 3) rot = 270;
500 wind->rotation = rot;
521 ecore_wl2_window_preferred_rotation_set(window, wind->rotation);
523 ecore_wl2_window_available_rotations_set(window, (const int*)checked, j);
527 SDL_Window *sdl_window = Tizen_FindWindow(SDL_GetVideoDevice(), window);
530 SDL_Log("Rotate error: sdl_window is null");
534 Tizen_rotate_update(sdl_window);
538 _tizen_window_orientation_add_hint(void *data)
540 SDL_WindowData *wind = (SDL_WindowData*)data;
541 if (wind->rotation_supported == 0)
544 SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, _tizen_window_orientaiton_hint_callback, data);
548 _tizen_cb_output_transform(void *data, int type EINA_UNUSED, void *event)
550 SDL_Window * window = SDL_GetVideoDevice()->windows;
551 SDL_WindowData *wind = window->driverdata;
553 if(!wind) return ECORE_CALLBACK_PASS_ON;
555 Ecore_Wl2_Event_Output_Transform *ev = event;
556 Ecore_Wl2_Output *output;
558 output = ecore_wl2_window_output_find(wind->window);
559 if (output != ev->output) return ECORE_CALLBACK_PASS_ON;
561 wind->received_rotation = TIZEN_ROTATION_RECEIVED_SCREEN_ROTATION;
564 return ECORE_CALLBACK_PASS_ON;
568 _tizen_cb_ignore_output_transform(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
570 SDL_Window * window = SDL_GetVideoDevice()->windows;
571 SDL_WindowData *wind = window->driverdata;
573 if(!wind) return ECORE_CALLBACK_PASS_ON;
575 wind->received_rotation = TIZEN_ROTATION_RECEIVED_SCREEN_ROTATION;
577 return ECORE_CALLBACK_PASS_ON;
581 _tizen_output_transform_register(SDL_WindowData *wind)
585 Ecore_Wl2_Output *output = ecore_wl2_window_output_find(wind->window);
586 wind->output_rotation = ecore_wl2_output_transform_get(output) * 90;
588 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_OUTPUT_TRANSFORM,
589 _tizen_cb_output_transform, NULL));
590 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_IGNORE_OUTPUT_TRANSFORM,
591 _tizen_cb_ignore_output_transform, NULL));
595 _tizen_indicator_opacity_hint_callback(void *userdata, const char *name, const char *oldValue, const char *newValue)
597 SDL_VideoData *data = (SDL_VideoData *)userdata;
599 if ((oldValue == NULL) && (newValue == NULL))
602 SDL_assert(SDL_strncmp(name, SDL_HINT_TIZEN_INDICATOR_OPACITY, SDL_strlen(SDL_HINT_TIZEN_INDICATOR_OPACITY)) == 0);
603 char indicator_type[4][20] = {"opaque","translucent","transparent","bg_transparent"};
604 for (int i=0;i<4;i++) {
605 if(SDL_strncmp(newValue, indicator_type[i], SDL_strlen(indicator_type[i])) == 0)
607 data->indicator_mode = i+1;
614 SDL_Tizen_GetSupportedAuxiliaryHintCount(SDL_Window *window)
616 SDL_WindowData *wind = NULL;
617 Ecore_Wl2_Window *ecore_window = NULL;
618 Eina_List* hints = NULL;
620 if (!window || !window->driverdata) {
624 wind = (SDL_WindowData *) window->driverdata;
625 ecore_window = wind->window;
627 SDL_Log("AddAuxiliaryHint: ecore_window is null");
631 hints = ecore_wl2_window_aux_hints_supported_get(ecore_window);
635 for (l = hints; l; l = eina_list_next(l)) {
643 SDL_Tizen_GetSupportedAuxiliaryHint(SDL_Window *window, unsigned int index)
645 SDL_WindowData *wind = NULL;
646 Ecore_Wl2_Window *ecore_window = NULL;
647 Eina_List* hints = NULL;
649 if (!window || !window->driverdata) {
653 wind = (SDL_WindowData *) window->driverdata;
654 ecore_window = wind->window;
656 SDL_Log("AddAuxiliaryHint: ecore_window is null");
660 hints = ecore_wl2_window_aux_hints_supported_get(ecore_window);
664 char* supported_hint = NULL;
666 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)))) {
668 return supported_hint;
677 SDL_Tizen_GetNativeWindow(SDL_Window *window)
679 SDL_WindowData *wind = NULL;
680 Ecore_Wl2_Window *ecore_window = NULL;
682 if (!window || !window->driverdata) {
686 wind = (SDL_WindowData *) window->driverdata;
688 ecore_window = wind->window;
695 SDL_Tizen_AddAuxiliaryHint(SDL_Window *window, const char *hint, const char *value)
697 SDL_WindowData *wind = NULL;
698 Ecore_Wl2_Window *ecore_window = NULL;
699 Eina_List* hints = NULL;
700 SDL_bool supported = SDL_FALSE;
702 if (!window || !window->driverdata) {
706 wind = (SDL_WindowData *) window->driverdata;
707 ecore_window = wind->window;
709 SDL_Log("AddAuxiliaryHint: ecore_window is null");
713 hints = ecore_wl2_window_aux_hints_supported_get(ecore_window);
716 char* supported_hint = NULL;
717 for (l = hints, (supported_hint = (char*)(eina_list_data_get(l))); l; l = eina_list_next(l),
718 (supported_hint = (char*)(eina_list_data_get(l)))) {
719 if (!SDL_strncmp(supported_hint, hint, strlen(hint))) {
720 supported = SDL_TRUE;
728 SDL_Log("AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint);
732 unsigned int new_id = 1;
733 if ((wind->auxiliaryHints).auxHintHeader) {
734 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
735 AuxiliaryHint* nextAuxiliaryHint = auxiliaryHint->next;
736 while (auxiliaryHint) {
737 if (!SDL_strncmp(auxiliaryHint->hint, hint, strlen(hint))) {
738 auxiliaryHint->value = value;
739 SDL_Log("AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", auxiliaryHint->hint, auxiliaryHint->value, auxiliaryHint->id);
740 return auxiliaryHint->id;
742 auxiliaryHint = nextAuxiliaryHint;
743 nextAuxiliaryHint = NULL;
745 nextAuxiliaryHint = auxiliaryHint->next;
752 AuxiliaryHint* newAuxiliaryHint = (AuxiliaryHint *)SDL_calloc(1, sizeof(AuxiliaryHint));
753 if (!newAuxiliaryHint) {
754 SDL_Log("AddAuxiliaryHint: Fail calloc");
758 newAuxiliaryHint->id = new_id;
759 newAuxiliaryHint->hint = hint;
760 newAuxiliaryHint->value = value;
761 newAuxiliaryHint->next = NULL;
763 newAuxiliaryHint->next = (wind->auxiliaryHints).auxHintHeader;
766 (wind->auxiliaryHints).auxHintHeader = newAuxiliaryHint;
767 (wind->auxiliaryHints).size++;
768 ecore_wl2_window_aux_hint_add(ecore_window, (int)new_id, hint, value);
769 SDL_Log("AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint, value, new_id);
775 SDL_Tizen_RemoveAuxiliaryHint(SDL_Window *window, unsigned int id)
777 SDL_WindowData *wind = NULL;
778 Ecore_Wl2_Window *ecore_window = NULL;
780 if (!window || !window->driverdata) {
784 wind = (SDL_WindowData *) window->driverdata;
785 ecore_window = wind->window;
788 SDL_Log("RemoveAuxiliaryHint: ecore_window is null");
793 SDL_Log( "RemoveAuxiliaryHint: Invalid id [%d]\n", id );
797 if ((wind->auxiliaryHints).auxHintHeader) {
798 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
799 AuxiliaryHint* prevAuxiliaryHint = NULL;
800 AuxiliaryHint* nextAuxiliaryHint = auxiliaryHint->next;
801 while (auxiliaryHint) {
802 if (auxiliaryHint->id == id) {
803 SDL_Log("RemoveAuxiliaryHint: id = %d, hint = %s\n", id, auxiliaryHint->hint);
804 ecore_wl2_window_aux_hint_del(ecore_window, (int)id);
805 if (auxiliaryHint == (wind->auxiliaryHints).auxHintHeader) {
806 (wind->auxiliaryHints).auxHintHeader = auxiliaryHint->next;
808 prevAuxiliaryHint->next = nextAuxiliaryHint;
810 SDL_free(auxiliaryHint);
811 (wind->auxiliaryHints).size--;
814 prevAuxiliaryHint = auxiliaryHint;
815 auxiliaryHint = nextAuxiliaryHint;
816 nextAuxiliaryHint = NULL;
818 nextAuxiliaryHint = auxiliaryHint->next;
826 SDL_Tizen_SetAuxiliaryHint(SDL_Window *window, unsigned int id, const char *value)
828 SDL_WindowData *wind = NULL;
829 Ecore_Wl2_Window *ecore_window = NULL;
831 if (!window || !window->driverdata) {
835 wind = (SDL_WindowData *) window->driverdata;
836 ecore_window = wind->window;
843 SDL_Log( "RemoveAuxiliaryHint: Invalid id [%d]\n", id );
847 if ((wind->auxiliaryHints).auxHintHeader) {
848 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
849 AuxiliaryHint* nextAuxiliaryHint = auxiliaryHint->next;
850 while (auxiliaryHint) {
851 if (auxiliaryHint->id == id) {
852 ecore_wl2_window_aux_hint_change(ecore_window, (int)id, value);
853 auxiliaryHint->value = value;
854 SDL_Log("SetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, auxiliaryHint->hint, auxiliaryHint->value);
857 auxiliaryHint = nextAuxiliaryHint;
858 nextAuxiliaryHint = NULL;
860 nextAuxiliaryHint = auxiliaryHint->next;
868 SDL_Tizen_GetAuxiliaryHintValue(SDL_Window *window, unsigned int id)
870 SDL_WindowData *wind = NULL;
871 if (!window || !window->driverdata) {
875 wind = (SDL_WindowData *) window->driverdata;
877 SDL_Log( "GetAuxiliaryHintValue: Invalid id [%d]\n", id );
881 if ((wind->auxiliaryHints).auxHintHeader) {
882 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
883 while (auxiliaryHint) {
884 if (auxiliaryHint->id == id) {
885 SDL_Log("GetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, auxiliaryHint->hint, auxiliaryHint->value);
886 return auxiliaryHint->value;
888 auxiliaryHint = auxiliaryHint->next;
895 SDL_Tizen_GetAuxiliaryHintId(SDL_Window *window, const char *hint)
897 SDL_WindowData *wind = NULL;
898 if (!window || !window->driverdata) {
902 wind = (SDL_WindowData *) window->driverdata;
904 if (hint == NULL || (wind->auxiliaryHints).size <= 0) {
905 SDL_Log( "GetAuxiliaryHintId: auxiliaryHints size is 0]\n");
909 if ((wind->auxiliaryHints).auxHintHeader) {
910 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
911 for (unsigned int i = 0; i < (wind->auxiliaryHints).size; i++) {
912 if (auxiliaryHint->hint == hint) {
913 SDL_Log("GetAuxiliaryHintId: hint = %s, id = %d\n", hint, auxiliaryHint->id);
914 return auxiliaryHint->id;
916 auxiliaryHint = auxiliaryHint->next;
919 SDL_Log("GetAuxiliaryHintId: Invalid hint! [%s]\n", hint);
925 SDL_Tizen_GetWindowAcceptFocus(SDL_Window * window)
927 SDL_WindowData *data = NULL;
929 if (!window || !window->driverdata) {
933 data = (SDL_WindowData *) window->driverdata;
938 return !ecore_wl2_window_focus_skip_get(data->window);
942 SDL_Tizen_SetWindowAcceptFocus(SDL_Window * window, SDL_bool accept)
944 SDL_WindowData *data = NULL;
946 if (!window || !window->driverdata) {
950 data = (SDL_WindowData *) window->driverdata;
955 ecore_wl2_window_focus_skip_set(data->window, !accept);
960 Tizen_CreateWindow(_THIS, SDL_Window *window)
962 SDL_VideoData *data = _this->driverdata;
963 SDL_WindowData *wind;
964 Ecore_Wl2_Global *global;
965 Eina_Iterator *globals;
966 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
967 Ecore_Wl2_Window *parent_wl2_window = NULL;
969 wind = calloc(1, sizeof * wind);
971 return SDL_OutOfMemory();
973 (wind->auxiliaryHints).size = 0;
974 (wind->auxiliaryHints).auxHintHeader = NULL;
975 window->driverdata = wind;
976 window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
978 #if SDL_VIDEO_OPENGL_EGL
979 if (window->flags & SDL_WINDOW_OPENGL) {
980 SDL_GL_LoadLibrary(NULL);
985 if (window->flags & SDL_WINDOW_VULKAN) {
986 if (!_this->Vulkan_GetInstanceExtensions) {
987 SDL_SetError("No Vulkan support in video driver");
990 if (_this->Vulkan_LoadLibrary(_this, NULL) < 0) {
991 SDL_SetError("Fail to load Vulkan Library");
996 if (window->x == SDL_WINDOWPOS_UNDEFINED) {
999 if (window->y == SDL_WINDOWPOS_UNDEFINED) {
1003 if (!(globals = ecore_wl2_display_globals_get(wl2_display)))
1005 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to get wayland globals");
1011 parent_wl2_window = ((SDL_WindowData *)(window->next->driverdata))->window;
1013 wind->window = ecore_wl2_window_new(wl2_display, parent_wl2_window,
1014 window->x, window->y, window->w, window->h);
1015 if (!wind->window) {
1016 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to create wayland window");
1018 eina_iterator_free(globals);
1022 ecore_wl2_window_position_set(wind->window, window->x, window->y);
1023 _tizen_output_transform_register(wind);
1025 wind->wl2_surface = ecore_wl2_surface_create(wind->window, EINA_FALSE);
1026 if (!wind->wl2_surface) {
1027 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to create wayland window surface");
1031 wind->surface = ecore_wl2_window_surface_get(wind->window);
1032 if (!wind->surface) {
1033 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to create wayland window surface");
1035 eina_iterator_free(globals);
1040 ecore_wl2_window_type_set(wind->window, ECORE_WL2_WINDOW_TYPE_UTILITY);
1043 wind->rotation_supported = 0;
1044 wind->received_rotation = TIZEN_ROTATION_RECEIVED_NONE;
1046 #if SDL_VIDEO_OPENGL_EGL
1047 if (window->flags & SDL_WINDOW_OPENGL) {
1049 if(wind->output_rotation == 90 || wind->output_rotation == 270)
1050 wind->egl_window = wl_egl_window_create(wind->surface, window->h, window->w);
1052 wind->egl_window = wl_egl_window_create(wind->surface, window->w, window->h);
1054 /* Create the GLES window surface */
1055 wind->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wind->egl_window);
1056 if (wind->egl_surface == EGL_NO_SURFACE) {
1057 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "failed to create a window surface");
1059 eina_iterator_free(globals);
1064 if (!_this->gl_config.alpha_size) {
1065 ecore_wl2_window_opaque_region_set(wind->window, window->x, window->y, window->w, window->h);
1068 wl_surface_set_opaque_region(wind->surface, NULL);
1071 //Support PreRotation
1072 wind->support_pre_rotation = 0;
1073 if (wl_egl_window_tizen_get_capabilities(wind->egl_window) == WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_SUPPORTED ) {
1074 wind->support_pre_rotation = 1;
1078 wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
1085 wind->id = ecore_wl2_window_id_get(wind->window);
1086 eina_hash_add(data->windows, &wind->id, window);
1088 Tizen_InitKeyboard(_this);
1089 SDL_SetMouseFocus(window);
1091 EINA_ITERATOR_FOREACH(globals, global) {
1092 if (!strcmp(global->interface, "tizen_policy_ext")) {
1093 wind->rotation_supported = 1;
1097 eina_iterator_free(globals);
1098 // Add orientaiton hint cb
1099 _tizen_window_orientation_add_hint((void*)wind);
1100 SDL_AddHintCallback(SDL_HINT_TIZEN_INDICATOR_OPACITY, _tizen_indicator_opacity_hint_callback, data);
1102 Tizen_rotate_update(window);
1108 Tizen_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
1112 SDL_WindowData *wind = window->driverdata;
1113 wind->support_indicator = SDL_FALSE;
1114 Tizen_TerminateIndicatorProcess(window->driverdata);
1119 Tizen_SetWindowSize(_THIS, SDL_Window *window)
1121 SDL_WindowData *wind = window->driverdata;
1122 if (!wind->egl_window)
1125 // TODO : consider to rotation status.
1126 #if SDL_VIDEO_OPENGL_EGL
1127 if (window->flags & SDL_WINDOW_OPENGL)
1129 int rotation = (wind->output_rotation + wind->rotation) % 360;
1130 if(rotation == 90 || rotation == 270)
1132 ecore_wl2_window_geometry_set(wind->window, window->y, window->x, window->h, window->w);
1133 wl_egl_window_resize(wind->egl_window, window->h, window->w, 0, 0);
1137 ecore_wl2_window_geometry_set(wind->window, window->x, window->y, window->w, window->h);
1138 wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
1141 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
1146 Tizen_GetWindowSize(_THIS, SDL_Window *window, int *w, int *h)
1148 SDL_WindowData *wind = window->driverdata;
1149 if (!wind->window) {
1153 if (w) *w = window->w;
1154 if (h) *h = window->h;
1158 Tizen_SetWindowPosition(_THIS, SDL_Window * window)
1160 SDL_WindowData *wind = window->driverdata;
1161 if (!wind->window) {
1165 // TODO : consider to rotation status.
1166 ecore_wl2_window_position_set(wind->window, window->x, window->y);
1170 Tizen_DestroyWindow(_THIS, SDL_Window *window)
1172 SDL_VideoData *data = _this->driverdata;
1173 SDL_WindowData *wind = window->driverdata;
1176 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
1177 if (auxiliaryHint) {
1178 AuxiliaryHint* nextAuxiliaryHints = auxiliaryHint->next;
1179 while (auxiliaryHint) {
1180 SDL_free(auxiliaryHint);
1181 auxiliaryHint = nextAuxiliaryHints;
1182 nextAuxiliaryHints = NULL;
1183 if (auxiliaryHint) {
1184 nextAuxiliaryHints = auxiliaryHint->next;
1188 eina_hash_del(data->windows, &wind->id, window);
1189 #if SDL_VIDEO_OPENGL_EGL
1190 if (window->flags & SDL_WINDOW_OPENGL) {
1191 SDL_EGL_DestroySurface(_this, wind->egl_surface);
1192 wl_egl_window_destroy(wind->egl_window);
1195 ecore_wl2_window_free(wind->window);
1199 window->driverdata = NULL;
1203 Tizen_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
1205 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
1206 if (opacity < 1.0f) {
1207 ecore_wl2_window_alpha_set(data->window, true);
1209 ecore_wl2_window_alpha_set(data->window, false);
1215 _tizen_cb_event_window_visibility_change(void *data, int type, void *event)
1218 Ecore_Wl2_Event_Window_Visibility_Change *ev;
1219 Ecore_Wl2_Window *ew;
1222 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
1226 ew = ecore_wl2_display_window_find(wl2_display, ev->win);
1227 window = Tizen_FindWindow(_this, ew);
1229 return ECORE_CALLBACK_PASS_ON;
1232 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0);
1233 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
1234 return ECORE_CALLBACK_PASS_ON;
1238 _tizen_cb_window_configure(void *data, int type EINA_UNUSED, void *event)
1241 Ecore_Wl2_Window *ew;
1243 SDL_WindowData *wind;
1244 Ecore_Wl2_Event_Window_Configure *ev;
1246 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
1249 ew = ecore_wl2_display_window_find(wl2_display, ev->win);
1250 window = Tizen_FindWindow(_this, ew);
1252 return ECORE_CALLBACK_PASS_ON;
1255 wind = window->driverdata;
1257 return ECORE_CALLBACK_PASS_ON;
1260 if (wind->rotation_supported == 0){
1261 return ECORE_CALLBACK_PASS_ON;
1264 return ECORE_CALLBACK_PASS_ON;
1268 _tizen_cb_event_window_rotate(void *data, int type EINA_UNUSED, void *event)
1271 Ecore_Wl2_Event_Window_Rotation *ev;
1272 Ecore_Wl2_Window *ew;
1274 SDL_WindowData *wind;
1276 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
1280 return ECORE_CALLBACK_PASS_ON;
1283 ew = ecore_wl2_display_window_find(wl2_display, ev->win);
1284 window = Tizen_FindWindow(_this, ew);
1286 return ECORE_CALLBACK_PASS_ON;
1289 wind = window->driverdata;
1291 return ECORE_CALLBACK_PASS_ON;
1294 /* set ecore_wl2 window rotation */
1295 wind->rotation = ev->angle;
1296 wind->received_rotation = TIZEN_ROTATION_RECEIVED_WINDOW_ROATION;
1298 return ECORE_CALLBACK_PASS_ON;
1301 static Eina_Bool _tizen_cb_event_window_show(void *data, int type, void *event)
1303 Ecore_Wl2_Event_Window_Show *e;
1304 uint32_t g_res_id = 0;
1308 g_res_id = e->data[0];
1312 SDL_VideoData *this = SDL_GetVideoDevice()->driverdata;
1313 SDL_Window * window = (SDL_Window*)eina_hash_find(this->windows, &e->win);
1316 SDL_Log("window is null");
1317 return ECORE_CALLBACK_PASS_ON;
1319 SDL_WindowData *wind = window->driverdata;
1322 SDL_Log("window->driverdata is null");
1323 return ECORE_CALLBACK_PASS_ON;
1325 wind->g_res_id = g_res_id;
1326 SDL_Log("[SDL] SDL Window Resource ID %d", g_res_id);
1329 return ECORE_CALLBACK_PASS_ON;
1333 Tizen_InitWindow(_THIS)
1335 SDL_VideoData *data = _this->driverdata;
1337 data->windows = eina_hash_int32_new(NULL);
1339 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE,
1340 _tizen_cb_event_window_visibility_change,_this));
1341 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_ROTATE,
1342 _tizen_cb_event_window_rotate,_this));
1343 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE,
1344 _tizen_cb_window_configure,_this));
1345 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_SHOW,
1346 _tizen_cb_event_window_show, _this));
1348 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_KEY_UP,
1349 _tizen_cb_event_keyup_change,_this));
1350 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
1351 _tizen_cb_event_keydown_change,_this));
1353 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
1354 _tizen_cb_event_mousedown_change,_this));
1355 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
1356 _tizen_cb_event_mouseup_change,_this));
1357 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE,
1358 _tizen_cb_event_mousemove_change,_this));
1359 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_MOUSE_IN,
1360 _tizen_cb_event_mouse_in,_this));
1361 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_MOUSE_OUT,
1362 _tizen_cb_event_mouse_out,_this));
1364 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN,
1365 _tizen_cb_event_focus_in,_this));
1366 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT,
1367 _tizen_cb_event_focus_out,_this));
1369 mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_JOYSTICK,
1370 _tizen_cb_event_joystick_change,_this));
1376 Tizen_DeinitWindow(_THIS)
1378 int size = mECoreEventHandler.size();
1379 for (int i = 0; i < size; i++)
1381 ecore_event_handler_del(*mECoreEventHandler[i]);
1383 mEcoreEventHandler.Clear();
1385 SDL_VideoData *data = _this->driverdata;
1387 eina_hash_free(data->windows);
1389 #endif /* SDL_VIDEO_DRIVER_TIZEN */
1391 /* vi: set ts=4 sw=4 expandtab: */