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