[SDL_Tizen] Add SDL_Window function
[platform/upstream/SDL.git] / src / video / tizen / SDL_tizenvideo.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   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.
9
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:
13
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.
21  */
22
23 #include "../../SDL_internal.h"
24
25 #if SDL_VIDEO_DRIVER_TIZEN
26
27 #include "SDL_video.h"
28 #include "SDL_mouse.h"
29 #include "SDL_stdinc.h"
30
31 #include "../../events/SDL_events_c.h"
32 #include "../../core/tizen/SDL_tizen.h"
33
34 #include "SDL_tizenvideo.h"
35 #include "SDL_tizenwindow.h"
36 #include "SDL_tizenkeyboard.h"
37 #include "SDL_tizenvulkan.h"
38 #include "SDL_tizenopengles.h"
39
40 #include "SDL_tizenevents_c.h"
41 #include "SDL_tizenmouse.h"
42
43
44 #define TIZENVID_DRIVER_NAME "tizen"
45
46 static void
47 _tizen_add_display(SDL_VideoData *d, uint32_t id)
48 {
49     SDL_VideoDisplay display;
50     SDL_DisplayMode mode;
51     static char *display_name = "tizen";
52
53     SDL_zero(display);
54     SDL_zero(mode);
55
56     display.name = display_name;
57
58     ecore_wl_screen_size_get(&mode.w, &mode.h);
59     mode.refresh_rate = 60; //Hz
60     mode.format = SDL_PIXELFORMAT_ARGB8888;
61
62     SDL_AddDisplayMode(&display, &mode);
63
64     display.current_mode = mode;
65     display.desktop_mode = mode;
66
67     SDL_AddVideoDisplay(&display);
68 }
69
70 /* Wayland driver bootstrap functions */
71 static int
72 Tizen_Available(void)
73 {
74     return 1;
75 }
76
77 static void
78 Tizen_DeleteDevice(SDL_VideoDevice *device)
79 {
80     SDL_free(device);
81 }
82
83 static SDL_VideoDevice *
84 Tizen_CreateDevice(int devindex)
85 {
86     SDL_VideoDevice *device;
87
88     /* Initialize all variables that we clean on shutdown */
89     device = SDL_calloc(1, sizeof(SDL_VideoDevice));
90     if (!device) {
91         SDL_OutOfMemory();
92         return NULL;
93     }
94
95     /* Tizen video */
96     device->VideoInit                           = Tizen_VideoInit;
97     device->VideoQuit                           = Tizen_VideoQuit;
98     device->SetDisplayMode                      = Tizen_SetDisplayMode;
99     device->GetDisplayModes             = Tizen_GetDisplayModes;
100     device->free                                        = Tizen_DeleteDevice;
101
102     device->PumpEvents = Tizen_PumpEvents;
103 #if SDL_VIDEO_OPENGL_EGL
104     device->GL_SwapWindow = Tizen_GLES_SwapWindow;
105     device->GL_GetSwapInterval = Tizen_GLES_GetSwapInterval;
106     device->GL_SetSwapInterval = Tizen_GLES_SetSwapInterval;
107     device->GL_MakeCurrent = Tizen_GLES_MakeCurrent;
108     device->GL_CreateContext = Tizen_GLES_CreateContext;
109     device->GL_LoadLibrary = Tizen_GLES_LoadLibrary;
110     device->GL_UnloadLibrary = Tizen_GLES_UnloadLibrary;
111     device->GL_GetProcAddress = Tizen_GLES_GetProcAddress;
112     device->GL_DeleteContext = Tizen_GLES_DeleteContext;
113 //    device->SetWindowBordered = Tizen_SetWindowBordered;
114 #endif
115     device->CreateWindow = Tizen_CreateWindow;
116     device->SetWindowTitle = Tizen_SetWindowTitle;
117     device->ShowWindow = Tizen_ShowWindow;
118     device->HideWindow = Tizen_HideWindow;
119     device->RaiseWindow = Tizen_RaiseWindow;
120     device->SetWindowFullscreen = Tizen_SetWindowFullscreen;
121     device->SetWindowSize = Tizen_SetWindowSize;
122     device->DestroyWindow = Tizen_DestroyWindow;
123     device->SetWindowHitTest = Tizen_SetWindowHitTest;
124     device->GetWindowWMInfo = Tizen_GetWindowWMInfo;
125     device->SetWindowPosition = Tizen_SetWindowPosition;
126
127     /* Text input */
128     device->StartTextInput = Tizen_StartTextInput;
129     device->StopTextInput = Tizen_StopTextInput;
130     //device->SetTextInputRect = Tizen_SetTextInputRect;
131
132     /* Screen keyboard */
133     device->HasScreenKeyboardSupport = Tizen_HasScreenKeyboardSupport;
134     device->ShowScreenKeyboard = Tizen_ShowScreenKeyboard;
135     //device->HideScreenKeyboard = Tizen_HideScreenKeyboard;
136     device->IsScreenKeyboardShown = Tizen_IsScreenKeyboardShown;
137
138 #if SDL_VIDEO_VULKAN
139     device->vulkan_GetInstanceExtensions = Tizen_vulkan_GetInstanceExtensions;
140     device->vulkan_CreateSurface = Tizen_vulkan_CreateSurface;
141     device->vulkan_LoadLibrary = Tizen_vulkan_LoadLibrary;
142 #endif
143     device->GetWindowSize = Tizen_GetWindowSize;
144
145     return device;
146 }
147
148 VideoBootStrap TIZEN_bootstrap = {
149     TIZENVID_DRIVER_NAME, "SDL tizen video driver",
150     Tizen_Available, Tizen_CreateDevice
151 };
152
153 int
154 Tizen_VideoInit(_THIS)
155 {
156     SDL_VideoData *data = SDL_malloc(sizeof * data);
157
158     if (data == NULL)
159         return SDL_OutOfMemory();
160     memset(data, 0, sizeof * data);
161
162     _this->driverdata = data;
163
164     ecore_wl_init(NULL);
165     _tizen_add_display(data, 0);
166     data->display = ecore_wl_display_get();
167
168     Tizen_InitWindow(_this);
169     Tizen_InitMouse();
170     return 0;
171 }
172
173 void
174 Tizen_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display)
175 {
176     SDL_Unsupported();
177 }
178
179 int
180 Tizen_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
181 {
182     return SDL_Unsupported();
183 }
184
185 void
186 Tizen_VideoQuit(_THIS)
187 {
188     SDL_VideoData *data = _this->driverdata;
189
190     Tizen_DeinitWindow(_this);
191     Tizen_FiniKeyboard();
192     Tizen_FiniMouse();
193
194     _tizen_ecore_ipc_client_send(OP_TERMINATE, 0, 0, 0);
195     SDL_tizen_app_exit();
196     ecore_wl_shutdown();
197     free(data);
198
199     _this->driverdata = NULL;
200 }
201
202
203 #endif /* SDL_VIDEO_DRIVER_TIZEN */
204
205 /* vi: set ts=4 sw=4 expandtab: */