upgrade SDL to version 2.0.8
[platform/upstream/SDL.git] / src / video / tizen / SDL_tizenopengles.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 #include "../../SDL_internal.h"
23
24 #if SDL_VIDEO_OPENGL_EGL
25
26 #include "SDL_log.h"
27 #include "SDL_hints.h"
28 #include "SDL_tizenopengles.h"
29 #include "SDL_tizenvideo.h"
30 #include "SDL_tizenwindow.h"
31
32 #include "../../events/SDL_windowevents_c.h"
33
34 #if SDL_VIDEO_OPENGL
35 #include "SDL_opengl.h"
36 #endif /* SDL_VIDEO_OPENGL */
37
38 #if SDL_VIDEO_OPENGL_ES
39 #include "SDL_opengles.h"
40 #endif /* SDL_VIDEO_OPENGL_ES */
41
42 /* GL and GLES2 headers conflict on Linux 32 bits */
43 #if SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL
44 #include "SDL_opengles2.h"
45 #endif /* SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL */
46
47 int
48 Tizen_GLES_LoadLibrary(_THIS, const char *path)
49 {
50     int ret;
51
52     Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
53
54     ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)ecore_wl2_display_get(wl2_display), 0);
55     return ret;
56 }
57
58 SDL_GLContext
59 Tizen_GLES_CreateContext(_THIS, SDL_Window *window)
60 {
61     SDL_GLContext context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
62     return context;
63 }
64
65 void
66 Tizen_GLES_SwapWindow(_THIS, SDL_Window *window)
67 {
68     SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
69     SDL_WindowData* wind = (SDL_WindowData*)window->driverdata;
70     int x, y, w, h;
71     if (wind->received_rotation != TIZEN_ROTATION_RECEIVED_NONE) {
72         Tizen_rotate_update(window);
73
74         ecore_wl2_window_geometry_get(wind->window, &x, &y, &w, &h);
75
76         if(wind->received_rotation == TIZEN_ROTATION_RECEIVED_WINDOW_ROATION)
77             ecore_wl2_window_rotation_change_done_send(wind->window, wind->rotation, w, h);
78
79         wind->received_rotation = TIZEN_ROTATION_RECEIVED_NONE;
80
81         SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
82         if(videoData->indicator_on && wind->support_indicator)
83         {
84             videoData->indicator_parent_id = wind->id;
85             _tizen_ecore_ipc_client_send(OP_INDICATOR_SHOW, wind->rotation, wind->g_res_id, 0);
86             _tizen_quickpanel_on(window->driverdata);
87         }
88     }
89 }
90
91 int
92 Tizen_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
93 {
94     int ret;
95
96     if (window && context) {
97         ret = SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context);
98     }
99     else if(!window && context) {
100         ret = SDL_EGL_MakeCurrent(_this, NULL, context);
101     }
102     else {
103         ret = SDL_EGL_MakeCurrent(_this, NULL, NULL);
104     }
105
106     return ret;
107 }
108
109 void
110 Tizen_GLES_DeleteContext(_THIS, SDL_GLContext context)
111 {
112     SDL_EGL_DeleteContext(_this, context);
113 }
114
115 int
116 Tizen_GLES_GetAlphaSize(_THIS)
117 {
118     EGLint alpha_size = 0;
119
120     if (!_this->egl_data) {
121         /* The EGL library wasn't loaded, SDL_GetError() should have info */
122         SDL_Log("egl_data is NULL");
123         return 0;
124     }
125
126     if (_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
127                                             _this->egl_data->egl_config,
128                                             EGL_ALPHA_SIZE,
129                                             &alpha_size) == EGL_FALSE || !alpha_size) {
130         alpha_size = 0;
131     }
132     return alpha_size;
133 }
134
135 #endif /* SDL_VIDEO_DRIVER_TIZEN && SDL_VIDEO_OPENGL_EGL */
136
137 /* vi: set ts=4 sw=4 expandtab: */