+
+#include "../SDL_egl_c.h"
+#include "../SDL_vulkan_c.h"
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_windowevents_c.h"
+
+#include <Ecore_Ipc.h>
+#include <unistd.h>
+#include <errno.h>
+
+enum {
+ ROTATION_TYPE_NORMAL_ROTATION = 0,
+ ROTATION_TYPE_PRE_ROTATION, /* use pre-rotation */
+};
+
+#define LOAD_FUNC(NAME) \
+_this->tizen_pre_rotation_data->NAME = SDL_LoadFunction(_this->tizen_pre_rotation_data->prerotation_dll_handle, #NAME); \
+if (!_this->tizen_pre_rotation_data->NAME) \
+{ \
+ SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Could not retrieve pre-rotation function " #NAME); \
+ return SDL_FALSE; \
+}
+
+/*SDL indicator*/
+
+
+
+Ecore_Ipc_Server *ipc = NULL;
+
+#define IPC_HEAD(_type) \
+ Ecore_Ipc_Event_Client_##_type *e = event; \
+ if (ecore_ipc_client_server_get(e->client) != ipc) \
+ return ECORE_CALLBACK_PASS_ON
+
+void SDL_ExecuteIndicatorProcess()
+{
+ _tizen_init_ecore_ipc();
+ unsigned int childPID = fork();
+ if(childPID == 0)
+ {
+ SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] child process : %d", getpid());
+ int ret = execl("/usr/apps/org.tizen.sdl_indicator/bin/sdl_indicator", "/usr/apps/org.tizen.sdl_indicator/bin/sdl_indicator", NULL);
+ if(ret==-1)
+ {
+ SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Failed indicator process error:%s", strerror(errno));
+ kill(getpid(), SIGKILL);
+ }
+ }
+ else if(childPID==-1)
+ {
+ SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Failed fork");
+ }
+ else
+ {
+ SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] parent process : %d", getpid());
+ }
+}
+
+void _tizen_ecore_ipc_client_send(int major, int minor, int ref, int ref_to)
+{
+ Eina_List *ipc_clients = ecore_ipc_server_clients_get(ipc);
+ Eina_List *l;
+ Ecore_Ipc_Client *cl;
+ EINA_LIST_FOREACH(ipc_clients, l, cl)
+ ecore_ipc_client_send(cl, major, minor, ref, ref_to, 0, NULL, 0);
+}
+
+static Eina_Bool _cb_client_add(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
+{
+ IPC_HEAD(Add);
+
+ SDL_Log("[SDL]_cb_client_add");
+ SDL_Window * window = SDL_GetVideoDevice()->windows;
+ SDL_WindowData *wind = window->driverdata;
+ wind->indicator = SDL_TRUE;
+
+ int window_w, window_h;
+ ecore_wl_screen_size_get(&window_w, &window_h);
+ _tizen_ecore_ipc_client_send(OP_RESIZE, wind->rotation, window_w, window_h);
+
+ return ECORE_CALLBACK_DONE;
+}
+
+static Eina_Bool _cb_client_del(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
+{
+ IPC_HEAD(Del);
+ SDL_Log("[SDL]_cb_client_del");
+ Eina_List *ipc_clients = ecore_ipc_server_clients_get(ipc);
+ Eina_List *l;
+ Ecore_Ipc_Client *cl;
+ EINA_LIST_FOREACH(ipc_clients, l, cl)
+ {
+ ecore_ipc_client_del(cl);
+ }
+
+ SDL_Window * window = SDL_GetVideoDevice()->windows;
+ SDL_WindowData *wind = window->driverdata;
+ wind->indicator = SDL_FALSE;
+ return ECORE_CALLBACK_DONE;
+}
+
+static Eina_Bool _cb_client_data(void *data, int type EINA_UNUSED, void *event)
+{
+ IPC_HEAD(Data);
+
+ Ecore_Ipc_Event_Server_Data* epcEvent = (Ecore_Ipc_Event_Server_Data*)event;
+ SDL_Log("[SDL]_cb_client_data: %d -> %d", epcEvent->major, epcEvent->minor);
+ return ECORE_CALLBACK_DONE;
+}
+
+int _tizen_init_ecore_ipc()
+{
+
+ if(!ipc)
+ {
+ if(!ecore_ipc_init())
+ SDL_Log("[SDL]Fail ecore_ipc");
+
+ ipc = ecore_ipc_server_add(ECORE_IPC_LOCAL_USER, "sdl_indicator", 0, NULL);
+
+ if(!ipc)
+ ecore_ipc_shutdown();
+
+ ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, _cb_client_add, NULL);
+ ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, _cb_client_del, NULL);
+ ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA, _cb_client_data, NULL);
+ }
+ return 0;
+}
+
+static int
+_tizen_rotation_type_get()
+{
+ static int type = ROTATION_TYPE_PRE_ROTATION;
+ static int checked = 0;
+ char *engine = NULL;
+
+ if (checked) return type;
+
+ engine = getenv("SDL_ROTATION");
+
+ if (engine)
+ {
+ if ((!strcasecmp(engine, "normal")))
+ type = ROTATION_TYPE_NORMAL_ROTATION;
+ else if ((!strcasecmp(engine, "pre_rotation")))
+ type = ROTATION_TYPE_PRE_ROTATION;
+ else
+ type = ROTATION_TYPE_PRE_ROTATION;
+ }
+ checked = 1;
+ return type;
+}