[Tizen] Add Tizen Video and Main
[platform/upstream/SDL.git] / src / video / tizen / SDL_tizenwindow.c
1 /*
2   Simple DirectMedia Layer
3   Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4   Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
5
6   Contact: Sangjin Lee <lsj119@samsung.com>
7
8   This software is provided 'as-is', without any express or implied
9   warranty.  In no event will the authors be held liable for any damages
10   arising from the use of this software.
11
12   Permission is granted to anyone to use this software for any purpose,
13   including commercial applications, and to alter it and redistribute it
14   freely, subject to the following restrictions:
15
16   1. The origin of this software must not be misrepresented; you must not
17      claim that you wrote the original software. If you use this software
18      in a product, an acknowledgment in the product documentation would be
19      appreciated but is not required.
20   2. Altered source versions must be plainly marked as such, and must not be
21      misrepresented as being the original software.
22   3. This notice may not be removed or altered from any source distribution.
23 */
24
25 #include "../../SDL_internal.h"
26
27 #if SDL_VIDEO_DRIVER_TIZEN && SDL_VIDEO_OPENGL_EGL
28
29 #include "../SDL_sysvideo.h"
30 #include "../../events/SDL_windowevents_c.h"
31 #include "../SDL_egl_c.h"
32 #include "SDL_tizenwindow.h"
33 #include "SDL_tizenvideo.h"
34 #include "SDL_tizentouch.h"
35
36 #include <wayland-egl.h>
37
38 SDL_bool
39 Tizen_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
40 {
41     TRACE_ENTER();
42     return SDL_TRUE;
43 }
44
45 int
46 Tizen_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
47 {
48     TRACE_ENTER();
49     return 0;  /* just succeed, the real work is done elsewhere. */
50 }
51
52 void
53 Tizen_ShowWindow(_THIS, SDL_Window *window)
54 {
55     TRACE_ENTER();
56     SDL_WindowData *wind = window->driverdata;
57
58     ecore_wl_window_show(wind->window);
59 }
60
61 void
62 Tizen_SetWindowFullscreen(_THIS, SDL_Window *window,
63                           SDL_VideoDisplay *_display, SDL_bool fullscreen)
64 {
65     TRACE_ENTER();
66     /*DO NOTHING*/
67 }
68
69 int
70 Tizen_CreateWindow(_THIS, SDL_Window *window)
71 {
72     TRACE_ENTER();
73     SDL_VideoData *data = _this->driverdata;
74     SDL_WindowData *wind;
75
76     wind = calloc(1, sizeof * wind);
77     if (wind == NULL)
78         return SDL_OutOfMemory();
79
80     window->driverdata = wind;
81
82     if (!(window->flags & SDL_WINDOW_OPENGL)) {
83         SDL_GL_LoadLibrary(NULL);
84         window->flags |= SDL_WINDOW_OPENGL;
85     }
86
87     if (window->x == SDL_WINDOWPOS_UNDEFINED) {
88         window->x = 0;
89     }
90     if (window->y == SDL_WINDOWPOS_UNDEFINED) {
91         window->y = 0;
92     }
93
94     wind->window = ecore_wl_window_new(NULL,
95                                        window->x, window->y, window->w, window->h,
96                                        ECORE_WL_WINDOW_BUFFER_TYPE_SHM);
97     ecore_wl_window_surface_create(wind->window);
98
99     wind->egl_window = wl_egl_window_create(ecore_wl_window_surface_get(wind->window), window->w, window->h);
100
101     /* Create the GLES window surface */
102     wind->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wind->egl_window);
103     if (wind->egl_surface == EGL_NO_SURFACE) {
104         return SDL_SetError("failed to create a window surface");
105     }
106
107     wind->id = ecore_wl_window_id_get(wind->window);
108     eina_hash_add(data->windows, &wind->id, window);
109
110     return 0;
111 }
112
113 void
114 Tizen_SetWindowSize(_THIS, SDL_Window *window)
115 {
116     TRACE_ENTER();
117     SDL_WindowData *wind = window->driverdata;
118
119     wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
120 }
121
122 void
123 Tizen_DestroyWindow(_THIS, SDL_Window *window)
124 {
125     TRACE_ENTER();
126     SDL_VideoData *data = _this->driverdata;
127     SDL_WindowData *wind = window->driverdata;
128
129     if (data) {
130         eina_hash_del(data->windows, &wind->id, window);
131
132         SDL_EGL_DestroySurface(_this, wind->egl_surface);
133         wl_egl_window_destroy(wind->egl_window);
134         ecore_wl_window_free(wind->window);
135
136         SDL_free(wind);
137     }
138
139     window->driverdata = NULL;
140 }
141
142 static SDL_Window*
143 __tizen_find_window(_THIS, Ecore_Wl_Window *ewin)
144 {
145     SDL_VideoData *data = _this->driverdata;
146     int id;
147
148     id = ecore_wl_window_id_get(ewin);
149     return (SDL_Window*)eina_hash_find(data->windows, &id);
150 }
151
152 static Eina_Bool
153 __tizen_cb_window_visibility_change(void *data, int type, void *event)
154 {
155     _THIS = data;
156     Ecore_Wl_Event_Window_Visibility_Change *ev;
157     Ecore_Wl_Window *ew;
158     SDL_Window *window;
159
160     ev = event;
161     ew = ecore_wl_window_find(ev->win);
162     window = __tizen_find_window(_this, ew);
163
164     printf("SAMPLE EV : visibility window:%p, ecore_wl_window:%p\n", window, ew);
165     
166     return ECORE_CALLBACK_PASS_ON;
167 }
168
169 int 
170 Tizen_InitWindow(_THIS)
171 {
172     TRACE_ENTER();
173     SDL_VideoData *data = _this->driverdata;
174
175     data->windows = eina_hash_int32_new(NULL);
176     
177     ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
178                         __tizen_cb_window_visibility_change, _this);
179
180     return 0;
181 }
182
183 void
184 Tizen_DeinitWindow(_THIS)
185 {
186     TRACE_ENTER();
187     SDL_VideoData *data = _this->driverdata;
188
189     eina_hash_free(data->windows);
190 }
191 #endif /* SDL_VIDEO_DRIVER_TIZEN && SDL_VIDEO_OPENGL_EGL */
192
193 /* vi: set ts=4 sw=4 expandtab: */