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 Eina_Array *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 Ecore_Event_Handler *h;
237 h = ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, _cb_client_add, NULL);
238 eina_array_push(mEcoreEventHandler, h);
239 h = ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, _cb_client_del, NULL);
240 eina_array_push(mEcoreEventHandler, h);
241 h = ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA, _cb_client_data, NULL);
242 eina_array_push(mEcoreEventHandler, h);
248 Tizen_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
250 SDL_WindowData *wmdata = (SDL_WindowData *)window->driverdata;
251 info->info.tizen.egl_display = NULL;
252 info->info.tizen.egl_surface = NULL;
253 #if SDL_VIDEO_OPENGL_EGL
256 info->info.tizen.egl_display = (void*)_this->egl_data->egl_display;
258 info->info.tizen.egl_surface = (void*)wmdata->egl_surface;
260 info->subsystem = SDL_SYSWM_TIZEN;
265 Tizen_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
267 return 0; /* just succeed, the real work is done elsewhere. */
271 Tizen_SetWindowTitle(_THIS, SDL_Window * window)
273 SDL_WindowData *wind = window->driverdata;
274 ecore_wl2_window_title_set(wind->window, window->title);
278 Tizen_ShowWindow(_THIS, SDL_Window *window)
280 SDL_WindowData *wind = window->driverdata;
281 ecore_wl2_window_show(wind->window);
286 Tizen_HideWindow(_THIS, SDL_Window *window)
288 SDL_WindowData *wind = window->driverdata;
289 ecore_wl2_window_hide(wind->window);
293 Tizen_RaiseWindow(_THIS, SDL_Window *window)
295 SDL_WindowData *wind = window->driverdata;
296 ecore_wl2_window_iconified_set(wind->window, SDL_FALSE);
297 ecore_wl2_window_raise(wind->window);
301 Tizen_SetWindowFullscreen(_THIS, SDL_Window *window,
302 SDL_VideoDisplay *_display, SDL_bool fullscreen)
304 SDL_WindowData *wind = window->driverdata;
307 int screen_w, screen_h;
308 int rotation = (wind->output_rotation + wind->rotation) % 360;
309 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
311 if(rotation == 90 || rotation == 270)
312 ecore_wl2_display_screen_size_get(wl2_display, &screen_h, &screen_w);
314 ecore_wl2_display_screen_size_get(wl2_display, &screen_w, &screen_h);
316 _tizen_set_window_size(window, screen_w, screen_h);
317 Tizen_SetWindowSize(_this, window);
319 window->fullscreen_mode.w = screen_w;
320 window->fullscreen_mode.h = screen_h;
324 _tizen_set_window_size(SDL_Window * window, int w, int h)
328 SDL_SetError("Invalid window");
332 SDL_VideoDevice *_this = SDL_GetVideoDevice();
334 SDL_SetError("Video subsystem has not been initialized");
338 if (window->magic != &_this->window_magic) {
343 SDL_InvalidParamError("w");
347 SDL_InvalidParamError("h");
351 /* Make sure we don't exceed any window size limits */
352 if (window->min_w && w < window->min_w)
356 if (window->max_w && w > window->max_w)
360 if (window->min_h && h < window->min_h)
364 if (window->max_h && h > window->max_h)
369 if(window->flags & SDL_WINDOW_FULLSCREEN)
371 window->fullscreen_mode.w = w;
372 window->fullscreen_mode.h = h;
375 window->windowed.w = w;
376 window->windowed.h = h;
383 _tizen_send_rotation_event(SDL_Window *window, unsigned int angle)
386 SDL_WindowData *wind;
387 wind = window->driverdata;
389 SDL_memset(&event, 0, sizeof(event));
390 event.type = SDL_ROTATEEVENT;
392 if (wind->support_pre_rotation)
393 event.user.data1 = (void*)0;
395 event.user.data1 = (void*)angle;
396 event.user.data2 = (void*)-1;
398 SDL_PushEvent(&event);
403 _tizen_get_rotation_idx(int rotation)
405 return ((rotation % 360) / 90);
409 _tizen_rotation_do(SDL_Window *window, SDL_WindowData* wind, int rotation)
411 int window_w, window_h;
412 if(wind->rotation == 0 || wind->rotation == 180)
413 ecore_wl2_window_geometry_get(wind->window, 0, 0, &window_w, &window_h);
415 ecore_wl2_window_geometry_get(wind->window, 0, 0, &window_h, &window_w);
417 _tizen_set_window_size(window, window_w, window_h);
419 #if SDL_VIDEO_OPENGL_EGL
420 if (window->flags & SDL_WINDOW_OPENGL)
422 if(wind->support_pre_rotation)
424 wl_egl_window_tizen_set_rotation(wind->egl_window, 360 - rotation);
425 wl_egl_window_tizen_set_buffer_transform(wind->egl_window, _tizen_get_rotation_idx(rotation));
426 wl_egl_window_tizen_set_window_transform(wind->egl_window, _tizen_get_rotation_idx(wind->rotation));
430 wl_egl_window_resize(wind->egl_window, window_w, window_h, 0, 0);
431 wl_egl_window_tizen_set_buffer_transform(wind->egl_window, _tizen_get_rotation_idx((360 - wind->rotation)));
432 wl_egl_window_tizen_set_window_transform(wind->egl_window, _tizen_get_rotation_idx(0));
436 _tizen_send_rotation_event(window, 0);
437 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
442 Tizen_rotate_update(SDL_Window *window)
444 SDL_WindowData *wind = window->driverdata;
448 if (ecore_wl2_window_ignore_output_transform_get(wind->window))
454 Ecore_Wl2_Output *output = ecore_wl2_window_output_find(wind->window);
455 screen_rotation = ecore_wl2_output_transform_get(output) * 90;
458 //Set Screen Rotation
459 wind->output_rotation = screen_rotation;
461 ecore_wl2_window_rotation_set(wind->window, wind->rotation);
463 int rotation = (wind->output_rotation + wind->rotation) % 360;
464 _tizen_rotation_do(window, wind, rotation);
468 Tizen_FindWindow(_THIS, Ecore_Wl2_Window *ewin)
470 SDL_VideoData *data = _this->driverdata;
473 id = ecore_wl2_window_id_get(ewin);
474 return (SDL_Window*)eina_hash_find(data->windows, &id);
478 _tizen_window_orientaiton_hint_callback(void *userdata, const char *name, const char *oldValue, const char *newValue)
481 char orientation_type[4][20] = {"Portrait","LandscapeLeft","PortraitUpsideDown","LandscapeRight"};
482 int checked[4] = {0,};
485 SDL_WindowData *wind = (SDL_WindowData*)userdata;
486 Ecore_Wl2_Window *window = wind->window;
488 if (wind->rotation_supported == 0)
491 SDL_assert(SDL_strncmp(name, SDL_HINT_ORIENTATIONS, SDL_strlen(SDL_HINT_ORIENTATIONS)) == 0);
493 if ((oldValue == NULL) && (newValue == NULL))
497 p_str = SDL_strstr(newValue, orientation_type[i]);
499 if (p_str == newValue) {
502 else if (i == 1) rot = 90;
503 else if (i == 2) rot = 180;
504 else if (i == 3) rot = 270;
505 wind->rotation = rot;
526 ecore_wl2_window_preferred_rotation_set(window, wind->rotation);
528 ecore_wl2_window_available_rotations_set(window, (const int*)checked, j);
532 SDL_Window *sdl_window = Tizen_FindWindow(SDL_GetVideoDevice(), window);
535 SDL_Log("Rotate error: sdl_window is null");
539 Tizen_rotate_update(sdl_window);
543 _tizen_window_orientation_add_hint(void *data)
545 SDL_WindowData *wind = (SDL_WindowData*)data;
546 if (wind->rotation_supported == 0)
549 SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, _tizen_window_orientaiton_hint_callback, data);
553 _tizen_cb_output_transform(void *data, int type EINA_UNUSED, void *event)
555 SDL_Window * window = SDL_GetVideoDevice()->windows;
556 SDL_WindowData *wind = window->driverdata;
558 if(!wind) return ECORE_CALLBACK_PASS_ON;
560 Ecore_Wl2_Event_Output_Transform *ev = event;
561 Ecore_Wl2_Output *output;
563 output = ecore_wl2_window_output_find(wind->window);
564 if (output != ev->output) return ECORE_CALLBACK_PASS_ON;
566 wind->received_rotation = TIZEN_ROTATION_RECEIVED_SCREEN_ROTATION;
569 return ECORE_CALLBACK_PASS_ON;
573 _tizen_cb_ignore_output_transform(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
575 SDL_Window * window = SDL_GetVideoDevice()->windows;
576 SDL_WindowData *wind = window->driverdata;
578 if(!wind) return ECORE_CALLBACK_PASS_ON;
580 wind->received_rotation = TIZEN_ROTATION_RECEIVED_SCREEN_ROTATION;
582 return ECORE_CALLBACK_PASS_ON;
586 _tizen_output_transform_register(SDL_WindowData *wind)
590 Ecore_Wl2_Output *output = ecore_wl2_window_output_find(wind->window);
591 wind->output_rotation = ecore_wl2_output_transform_get(output) * 90;
593 Ecore_Event_Handler *h;
595 h = ecore_event_handler_add(ECORE_WL2_EVENT_OUTPUT_TRANSFORM,
596 _tizen_cb_output_transform, NULL);
597 eina_array_push(mEcoreEventHandler, h);
598 h = ecore_event_handler_add(ECORE_WL2_EVENT_IGNORE_OUTPUT_TRANSFORM,
599 _tizen_cb_ignore_output_transform, NULL);
600 eina_array_push(mEcoreEventHandler, h);
604 _tizen_indicator_opacity_hint_callback(void *userdata, const char *name, const char *oldValue, const char *newValue)
606 SDL_VideoData *data = (SDL_VideoData *)userdata;
608 if ((oldValue == NULL) && (newValue == NULL))
611 SDL_assert(SDL_strncmp(name, SDL_HINT_TIZEN_INDICATOR_OPACITY, SDL_strlen(SDL_HINT_TIZEN_INDICATOR_OPACITY)) == 0);
612 char indicator_type[4][20] = {"opaque","translucent","transparent","bg_transparent"};
613 for (int i=0;i<4;i++) {
614 if(SDL_strncmp(newValue, indicator_type[i], SDL_strlen(indicator_type[i])) == 0)
616 data->indicator_mode = i+1;
623 SDL_Tizen_GetSupportedAuxiliaryHintCount(SDL_Window *window)
625 SDL_WindowData *wind = NULL;
626 Ecore_Wl2_Window *ecore_window = NULL;
627 Eina_List* hints = NULL;
629 if (!window || !window->driverdata) {
633 wind = (SDL_WindowData *) window->driverdata;
634 ecore_window = wind->window;
636 SDL_Log("AddAuxiliaryHint: ecore_window is null");
640 hints = ecore_wl2_window_aux_hints_supported_get(ecore_window);
644 for (l = hints; l; l = eina_list_next(l)) {
652 SDL_Tizen_GetSupportedAuxiliaryHint(SDL_Window *window, unsigned int index)
654 SDL_WindowData *wind = NULL;
655 Ecore_Wl2_Window *ecore_window = NULL;
656 Eina_List* hints = NULL;
658 if (!window || !window->driverdata) {
662 wind = (SDL_WindowData *) window->driverdata;
663 ecore_window = wind->window;
665 SDL_Log("AddAuxiliaryHint: ecore_window is null");
669 hints = ecore_wl2_window_aux_hints_supported_get(ecore_window);
673 char* supported_hint = NULL;
675 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)))) {
677 return supported_hint;
686 SDL_Tizen_GetNativeWindow(SDL_Window *window)
688 SDL_WindowData *wind = NULL;
689 Ecore_Wl2_Window *ecore_window = NULL;
691 if (!window || !window->driverdata) {
695 wind = (SDL_WindowData *) window->driverdata;
697 ecore_window = wind->window;
704 SDL_Tizen_AddAuxiliaryHint(SDL_Window *window, const char *hint, const char *value)
706 SDL_WindowData *wind = NULL;
707 Ecore_Wl2_Window *ecore_window = NULL;
708 Eina_List* hints = NULL;
709 SDL_bool supported = SDL_FALSE;
711 if (!window || !window->driverdata) {
715 wind = (SDL_WindowData *) window->driverdata;
716 ecore_window = wind->window;
718 SDL_Log("AddAuxiliaryHint: ecore_window is null");
722 hints = ecore_wl2_window_aux_hints_supported_get(ecore_window);
725 char* supported_hint = NULL;
726 for (l = hints, (supported_hint = (char*)(eina_list_data_get(l))); l; l = eina_list_next(l),
727 (supported_hint = (char*)(eina_list_data_get(l)))) {
728 if (!SDL_strncmp(supported_hint, hint, strlen(hint))) {
729 supported = SDL_TRUE;
737 SDL_Log("AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint);
741 unsigned int new_id = 1;
742 if ((wind->auxiliaryHints).auxHintHeader) {
743 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
744 AuxiliaryHint* nextAuxiliaryHint = auxiliaryHint->next;
745 while (auxiliaryHint) {
746 if (!SDL_strncmp(auxiliaryHint->hint, hint, strlen(hint))) {
747 auxiliaryHint->value = value;
748 SDL_Log("AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", auxiliaryHint->hint, auxiliaryHint->value, auxiliaryHint->id);
749 return auxiliaryHint->id;
751 auxiliaryHint = nextAuxiliaryHint;
752 nextAuxiliaryHint = NULL;
754 nextAuxiliaryHint = auxiliaryHint->next;
761 AuxiliaryHint* newAuxiliaryHint = (AuxiliaryHint *)SDL_calloc(1, sizeof(AuxiliaryHint));
762 if (!newAuxiliaryHint) {
763 SDL_Log("AddAuxiliaryHint: Fail calloc");
767 newAuxiliaryHint->id = new_id;
768 newAuxiliaryHint->hint = hint;
769 newAuxiliaryHint->value = value;
770 newAuxiliaryHint->next = NULL;
772 newAuxiliaryHint->next = (wind->auxiliaryHints).auxHintHeader;
775 (wind->auxiliaryHints).auxHintHeader = newAuxiliaryHint;
776 (wind->auxiliaryHints).size++;
777 ecore_wl2_window_aux_hint_add(ecore_window, (int)new_id, hint, value);
778 SDL_Log("AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint, value, new_id);
784 SDL_Tizen_RemoveAuxiliaryHint(SDL_Window *window, unsigned int id)
786 SDL_WindowData *wind = NULL;
787 Ecore_Wl2_Window *ecore_window = NULL;
789 if (!window || !window->driverdata) {
793 wind = (SDL_WindowData *) window->driverdata;
794 ecore_window = wind->window;
797 SDL_Log("RemoveAuxiliaryHint: ecore_window is null");
802 SDL_Log( "RemoveAuxiliaryHint: Invalid id [%d]\n", id );
806 if ((wind->auxiliaryHints).auxHintHeader) {
807 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
808 AuxiliaryHint* prevAuxiliaryHint = NULL;
809 AuxiliaryHint* nextAuxiliaryHint = auxiliaryHint->next;
810 while (auxiliaryHint) {
811 if (auxiliaryHint->id == id) {
812 SDL_Log("RemoveAuxiliaryHint: id = %d, hint = %s\n", id, auxiliaryHint->hint);
813 ecore_wl2_window_aux_hint_del(ecore_window, (int)id);
814 if (auxiliaryHint == (wind->auxiliaryHints).auxHintHeader) {
815 (wind->auxiliaryHints).auxHintHeader = auxiliaryHint->next;
817 prevAuxiliaryHint->next = nextAuxiliaryHint;
819 SDL_free(auxiliaryHint);
820 (wind->auxiliaryHints).size--;
823 prevAuxiliaryHint = auxiliaryHint;
824 auxiliaryHint = nextAuxiliaryHint;
825 nextAuxiliaryHint = NULL;
827 nextAuxiliaryHint = auxiliaryHint->next;
835 SDL_Tizen_SetAuxiliaryHint(SDL_Window *window, unsigned int id, const char *value)
837 SDL_WindowData *wind = NULL;
838 Ecore_Wl2_Window *ecore_window = NULL;
840 if (!window || !window->driverdata) {
844 wind = (SDL_WindowData *) window->driverdata;
845 ecore_window = wind->window;
852 SDL_Log( "RemoveAuxiliaryHint: Invalid id [%d]\n", id );
856 if ((wind->auxiliaryHints).auxHintHeader) {
857 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
858 AuxiliaryHint* nextAuxiliaryHint = auxiliaryHint->next;
859 while (auxiliaryHint) {
860 if (auxiliaryHint->id == id) {
861 ecore_wl2_window_aux_hint_change(ecore_window, (int)id, value);
862 auxiliaryHint->value = value;
863 SDL_Log("SetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, auxiliaryHint->hint, auxiliaryHint->value);
866 auxiliaryHint = nextAuxiliaryHint;
867 nextAuxiliaryHint = NULL;
869 nextAuxiliaryHint = auxiliaryHint->next;
877 SDL_Tizen_GetAuxiliaryHintValue(SDL_Window *window, unsigned int id)
879 SDL_WindowData *wind = NULL;
880 if (!window || !window->driverdata) {
884 wind = (SDL_WindowData *) window->driverdata;
886 SDL_Log( "GetAuxiliaryHintValue: Invalid id [%d]\n", id );
890 if ((wind->auxiliaryHints).auxHintHeader) {
891 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
892 while (auxiliaryHint) {
893 if (auxiliaryHint->id == id) {
894 SDL_Log("GetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, auxiliaryHint->hint, auxiliaryHint->value);
895 return auxiliaryHint->value;
897 auxiliaryHint = auxiliaryHint->next;
904 SDL_Tizen_GetAuxiliaryHintId(SDL_Window *window, const char *hint)
906 SDL_WindowData *wind = NULL;
907 if (!window || !window->driverdata) {
911 wind = (SDL_WindowData *) window->driverdata;
913 if (hint == NULL || (wind->auxiliaryHints).size <= 0) {
914 SDL_Log( "GetAuxiliaryHintId: auxiliaryHints size is 0]\n");
918 if ((wind->auxiliaryHints).auxHintHeader) {
919 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
920 for (unsigned int i = 0; i < (wind->auxiliaryHints).size; i++) {
921 if (auxiliaryHint->hint == hint) {
922 SDL_Log("GetAuxiliaryHintId: hint = %s, id = %d\n", hint, auxiliaryHint->id);
923 return auxiliaryHint->id;
925 auxiliaryHint = auxiliaryHint->next;
928 SDL_Log("GetAuxiliaryHintId: Invalid hint! [%s]\n", hint);
934 SDL_Tizen_GetWindowAcceptFocus(SDL_Window * window)
936 SDL_WindowData *data = NULL;
938 if (!window || !window->driverdata) {
942 data = (SDL_WindowData *) window->driverdata;
947 return !ecore_wl2_window_focus_skip_get(data->window);
951 SDL_Tizen_SetWindowAcceptFocus(SDL_Window * window, SDL_bool accept)
953 SDL_WindowData *data = NULL;
955 if (!window || !window->driverdata) {
959 data = (SDL_WindowData *) window->driverdata;
964 ecore_wl2_window_focus_skip_set(data->window, !accept);
969 Tizen_CreateWindow(_THIS, SDL_Window *window)
971 SDL_VideoData *data = _this->driverdata;
972 SDL_WindowData *wind;
973 Ecore_Wl2_Global *global;
974 Eina_Iterator *globals;
975 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
976 Ecore_Wl2_Window *parent_wl2_window = NULL;
978 wind = calloc(1, sizeof * wind);
980 return SDL_OutOfMemory();
982 (wind->auxiliaryHints).size = 0;
983 (wind->auxiliaryHints).auxHintHeader = NULL;
984 window->driverdata = wind;
985 window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
987 #if SDL_VIDEO_OPENGL_EGL
988 if (window->flags & SDL_WINDOW_OPENGL) {
989 SDL_GL_LoadLibrary(NULL);
994 if (window->flags & SDL_WINDOW_VULKAN) {
995 if (!_this->Vulkan_GetInstanceExtensions) {
996 SDL_SetError("No Vulkan support in video driver");
999 if (_this->Vulkan_LoadLibrary(_this, NULL) < 0) {
1000 SDL_SetError("Fail to load Vulkan Library");
1005 if (window->x == SDL_WINDOWPOS_UNDEFINED) {
1008 if (window->y == SDL_WINDOWPOS_UNDEFINED) {
1012 if (!(globals = ecore_wl2_display_globals_get(wl2_display)))
1014 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to get wayland globals");
1020 parent_wl2_window = ((SDL_WindowData *)(window->next->driverdata))->window;
1022 wind->window = ecore_wl2_window_new(wl2_display, parent_wl2_window,
1023 window->x, window->y, window->w, window->h);
1024 if (!wind->window) {
1025 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to create wayland window");
1027 eina_iterator_free(globals);
1031 ecore_wl2_window_position_set(wind->window, window->x, window->y);
1032 _tizen_output_transform_register(wind);
1034 wind->wl2_surface = ecore_wl2_surface_create(wind->window, EINA_FALSE);
1035 if (!wind->wl2_surface) {
1036 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to create wayland window surface");
1040 wind->surface = ecore_wl2_window_surface_get(wind->window);
1041 if (!wind->surface) {
1042 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to create wayland window surface");
1044 eina_iterator_free(globals);
1049 ecore_wl2_window_type_set(wind->window, ECORE_WL2_WINDOW_TYPE_UTILITY);
1052 wind->rotation_supported = 0;
1053 wind->received_rotation = TIZEN_ROTATION_RECEIVED_NONE;
1055 #if SDL_VIDEO_OPENGL_EGL
1056 if (window->flags & SDL_WINDOW_OPENGL) {
1058 if(wind->output_rotation == 90 || wind->output_rotation == 270)
1059 wind->egl_window = wl_egl_window_create(wind->surface, window->h, window->w);
1061 wind->egl_window = wl_egl_window_create(wind->surface, window->w, window->h);
1063 /* Create the GLES window surface */
1064 wind->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wind->egl_window);
1065 if (wind->egl_surface == EGL_NO_SURFACE) {
1066 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "failed to create a window surface");
1068 eina_iterator_free(globals);
1073 if (!_this->gl_config.alpha_size) {
1074 ecore_wl2_window_opaque_region_set(wind->window, window->x, window->y, window->w, window->h);
1077 wl_surface_set_opaque_region(wind->surface, NULL);
1080 //Support PreRotation
1081 wind->support_pre_rotation = 0;
1082 if (wl_egl_window_tizen_get_capabilities(wind->egl_window) == WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_SUPPORTED ) {
1083 wind->support_pre_rotation = 1;
1087 wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
1094 wind->id = ecore_wl2_window_id_get(wind->window);
1095 eina_hash_add(data->windows, &wind->id, window);
1097 Tizen_InitKeyboard(_this);
1098 SDL_SetMouseFocus(window);
1100 EINA_ITERATOR_FOREACH(globals, global) {
1101 if (!strcmp(global->interface, "tizen_policy_ext")) {
1102 wind->rotation_supported = 1;
1106 eina_iterator_free(globals);
1107 // Add orientaiton hint cb
1108 _tizen_window_orientation_add_hint((void*)wind);
1109 SDL_AddHintCallback(SDL_HINT_TIZEN_INDICATOR_OPACITY, _tizen_indicator_opacity_hint_callback, data);
1111 Tizen_rotate_update(window);
1117 Tizen_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
1121 SDL_WindowData *wind = window->driverdata;
1122 wind->support_indicator = SDL_FALSE;
1123 Tizen_TerminateIndicatorProcess(window->driverdata);
1128 Tizen_SetWindowSize(_THIS, SDL_Window *window)
1130 SDL_WindowData *wind = window->driverdata;
1131 if (!wind->egl_window)
1134 // TODO : consider to rotation status.
1135 #if SDL_VIDEO_OPENGL_EGL
1136 if (window->flags & SDL_WINDOW_OPENGL)
1138 int rotation = (wind->output_rotation + wind->rotation) % 360;
1139 if(rotation == 90 || rotation == 270)
1141 ecore_wl2_window_geometry_set(wind->window, window->y, window->x, window->h, window->w);
1142 wl_egl_window_resize(wind->egl_window, window->h, window->w, 0, 0);
1146 ecore_wl2_window_geometry_set(wind->window, window->x, window->y, window->w, window->h);
1147 wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
1150 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
1155 Tizen_GetWindowSize(_THIS, SDL_Window *window, int *w, int *h)
1157 SDL_WindowData *wind = window->driverdata;
1158 if (!wind->window) {
1162 if (w) *w = window->w;
1163 if (h) *h = window->h;
1167 Tizen_SetWindowPosition(_THIS, SDL_Window * window)
1169 SDL_WindowData *wind = window->driverdata;
1170 if (!wind->window) {
1174 // TODO : consider to rotation status.
1175 ecore_wl2_window_position_set(wind->window, window->x, window->y);
1179 Tizen_DestroyWindow(_THIS, SDL_Window *window)
1181 SDL_VideoData *data = _this->driverdata;
1182 SDL_WindowData *wind = window->driverdata;
1185 AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
1186 if (auxiliaryHint) {
1187 AuxiliaryHint* nextAuxiliaryHints = auxiliaryHint->next;
1188 while (auxiliaryHint) {
1189 SDL_free(auxiliaryHint);
1190 auxiliaryHint = nextAuxiliaryHints;
1191 nextAuxiliaryHints = NULL;
1192 if (auxiliaryHint) {
1193 nextAuxiliaryHints = auxiliaryHint->next;
1197 eina_hash_del(data->windows, &wind->id, window);
1198 #if SDL_VIDEO_OPENGL_EGL
1199 if (window->flags & SDL_WINDOW_OPENGL) {
1200 SDL_EGL_DestroySurface(_this, wind->egl_surface);
1201 wl_egl_window_destroy(wind->egl_window);
1204 ecore_wl2_window_free(wind->window);
1208 window->driverdata = NULL;
1212 Tizen_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
1214 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
1215 if (opacity < 1.0f) {
1216 ecore_wl2_window_alpha_set(data->window, true);
1218 ecore_wl2_window_alpha_set(data->window, false);
1224 _tizen_cb_event_window_visibility_change(void *data, int type, void *event)
1227 Ecore_Wl2_Event_Window_Visibility_Change *ev;
1228 Ecore_Wl2_Window *ew;
1231 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
1235 ew = ecore_wl2_display_window_find(wl2_display, ev->win);
1236 window = Tizen_FindWindow(_this, ew);
1238 return ECORE_CALLBACK_PASS_ON;
1241 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0);
1242 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
1243 return ECORE_CALLBACK_PASS_ON;
1247 _tizen_cb_window_configure(void *data, int type EINA_UNUSED, void *event)
1250 Ecore_Wl2_Window *ew;
1252 SDL_WindowData *wind;
1253 Ecore_Wl2_Event_Window_Configure *ev;
1255 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
1258 ew = ecore_wl2_display_window_find(wl2_display, ev->win);
1259 window = Tizen_FindWindow(_this, ew);
1261 return ECORE_CALLBACK_PASS_ON;
1264 wind = window->driverdata;
1266 return ECORE_CALLBACK_PASS_ON;
1269 if (wind->rotation_supported == 0){
1270 return ECORE_CALLBACK_PASS_ON;
1273 return ECORE_CALLBACK_PASS_ON;
1277 _tizen_cb_event_window_rotate(void *data, int type EINA_UNUSED, void *event)
1280 Ecore_Wl2_Event_Window_Rotation *ev;
1281 Ecore_Wl2_Window *ew;
1283 SDL_WindowData *wind;
1285 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
1289 return ECORE_CALLBACK_PASS_ON;
1292 ew = ecore_wl2_display_window_find(wl2_display, ev->win);
1293 window = Tizen_FindWindow(_this, ew);
1295 return ECORE_CALLBACK_PASS_ON;
1298 wind = window->driverdata;
1300 return ECORE_CALLBACK_PASS_ON;
1303 /* set ecore_wl2 window rotation */
1304 wind->rotation = ev->angle;
1305 wind->received_rotation = TIZEN_ROTATION_RECEIVED_WINDOW_ROATION;
1307 return ECORE_CALLBACK_PASS_ON;
1310 static Eina_Bool _tizen_cb_event_window_show(void *data, int type, void *event)
1312 Ecore_Wl2_Event_Window_Show *e;
1313 uint32_t g_res_id = 0;
1317 g_res_id = e->data[0];
1321 SDL_VideoData *this = SDL_GetVideoDevice()->driverdata;
1322 SDL_Window * window = (SDL_Window*)eina_hash_find(this->windows, &e->win);
1325 SDL_Log("window is null");
1326 return ECORE_CALLBACK_PASS_ON;
1328 SDL_WindowData *wind = window->driverdata;
1331 SDL_Log("window->driverdata is null");
1332 return ECORE_CALLBACK_PASS_ON;
1334 wind->g_res_id = g_res_id;
1335 SDL_Log("[SDL] SDL Window Resource ID %d", g_res_id);
1338 return ECORE_CALLBACK_PASS_ON;
1342 Tizen_InitWindow(_THIS)
1344 SDL_VideoData *data = _this->driverdata;
1346 data->windows = eina_hash_int32_new(NULL);
1347 Ecore_Event_Handler *h;
1349 h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE,
1350 _tizen_cb_event_window_visibility_change,_this);
1351 eina_array_push(mEcoreEventHandler, h);
1352 h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_ROTATE,
1353 _tizen_cb_event_window_rotate,_this);
1354 eina_array_push(mEcoreEventHandler, h);
1355 h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE,
1356 _tizen_cb_window_configure,_this);
1357 eina_array_push(mEcoreEventHandler, h);
1358 h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_SHOW,
1359 _tizen_cb_event_window_show, _this);
1360 eina_array_push(mEcoreEventHandler, h);
1362 h = ecore_event_handler_add(ECORE_EVENT_KEY_UP,
1363 _tizen_cb_event_keyup_change,_this);
1364 eina_array_push(mEcoreEventHandler, h);
1365 h = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
1366 _tizen_cb_event_keydown_change,_this);
1367 eina_array_push(mEcoreEventHandler, h);
1369 h = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
1370 _tizen_cb_event_mousedown_change,_this);
1371 eina_array_push(mEcoreEventHandler, h);
1372 h = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
1373 _tizen_cb_event_mouseup_change,_this);
1374 eina_array_push(mEcoreEventHandler, h);
1375 h = ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE,
1376 _tizen_cb_event_mousemove_change,_this);
1377 eina_array_push(mEcoreEventHandler, h);
1378 h = ecore_event_handler_add(ECORE_EVENT_MOUSE_IN,
1379 _tizen_cb_event_mouse_in,_this);
1380 eina_array_push(mEcoreEventHandler, h);
1381 h = ecore_event_handler_add(ECORE_EVENT_MOUSE_OUT,
1382 _tizen_cb_event_mouse_out,_this);
1383 eina_array_push(mEcoreEventHandler, h);
1385 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN,
1386 _tizen_cb_event_focus_in,_this);
1387 eina_array_push(mEcoreEventHandler, h);
1388 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT,
1389 _tizen_cb_event_focus_out,_this);
1390 eina_array_push(mEcoreEventHandler, h);
1392 h = ecore_event_handler_add(ECORE_EVENT_JOYSTICK,
1393 _tizen_cb_event_joystick_change,_this);
1394 eina_array_push(mEcoreEventHandler, h);
1400 Tizen_DeinitWindow(_THIS)
1402 if (mEcoreEventHandler)
1404 while (eina_array_count(mEcoreEventHandler))
1405 ecore_event_handler_del(eina_array_pop(mEcoreEventHandler));
1406 eina_array_free(mEcoreEventHandler);
1409 SDL_VideoData *data = _this->driverdata;
1411 eina_hash_free(data->windows);
1413 #endif /* SDL_VIDEO_DRIVER_TIZEN */
1415 /* vi: set ts=4 sw=4 expandtab: */