summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <c.bail@partner.samsung.com>2014-07-25 20:23:42 +0200
committerCedric BAIL <c.bail@partner.samsung.com>2014-07-25 20:24:29 +0200
commit3c179cdb87446f58b7eec3b467c9142c9a97df96 (patch)
tree21d05b1e03f6473110201d3109d495b7dbedc2a6
parent9a9d78dfcbe2aa75ecc72d0fe303a174d0ed457a (diff)
evas: move to SDL2 and use GL_Generic infrastructure.
-rw-r--r--configure.ac7
-rw-r--r--m4/evas_check_engine.m44
-rw-r--r--src/Makefile_Evas.am10
-rw-r--r--src/lib/ecore_sdl/Ecore_Sdl.h31
-rw-r--r--src/lib/ecore_sdl/Ecore_Sdl_Keys.h139
-rw-r--r--src/lib/ecore_sdl/ecore_sdl.c163
-rw-r--r--src/modules/ecore_evas/engines/sdl/ecore_evas_sdl.c243
-rw-r--r--src/modules/evas/engines/gl_sdl/Evas_Engine_GL_SDL.h5
-rw-r--r--src/modules/evas/engines/gl_sdl/evas_engine.c1099
-rw-r--r--src/modules/evas/engines/gl_sdl/evas_engine.h23
10 files changed, 575 insertions, 1149 deletions
diff --git a/configure.ac b/configure.ac
index da1c7a9b08..1cbc698d69 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1239,7 +1239,7 @@ AC_ARG_ENABLE([sdl],
1239 [want_sdl="no"]) 1239 [want_sdl="no"])
1240 1240
1241if test "${want_sdl}" = "yes"; then 1241if test "${want_sdl}" = "yes"; then
1242 EFL_PKG_CHECK_STRICT([sdl >= 1.2.0]) 1242 EFL_PKG_CHECK_STRICT([sdl2 >= 2.0.0])
1243fi 1243fi
1244 1244
1245# We only enable SDL with opengl if it is not the full version and not ES 1245# We only enable SDL with opengl if it is not the full version and not ES
@@ -2734,10 +2734,7 @@ EFL_INTERNAL_DEPEND_PKG([ECORE_SDL], [ecore])
2734EFL_INTERNAL_DEPEND_PKG([ECORE_SDL], [eo]) 2734EFL_INTERNAL_DEPEND_PKG([ECORE_SDL], [eo])
2735EFL_INTERNAL_DEPEND_PKG([ECORE_SDL], [eina]) 2735EFL_INTERNAL_DEPEND_PKG([ECORE_SDL], [eina])
2736 2736
2737EFL_DEPEND_PKG([ECORE_SDL], [SDL], [sdl >= 1.2.0]) 2737EFL_DEPEND_PKG([ECORE_SDL], [SDL], [sdl2 >= 2.0.0])
2738
2739PKG_CHECK_EXISTS([sdl >= 1.3.0],
2740 [AC_DEFINE(BUILD_ECORE_EVAS_SDL_130, 1, [Support for SVN SDL])])
2741 2738
2742EFL_EVAL_PKGS([ECORE_SDL]) 2739EFL_EVAL_PKGS([ECORE_SDL])
2743 2740
diff --git a/m4/evas_check_engine.m4 b/m4/evas_check_engine.m4
index 05ec1f8d7a..dd7030e5cf 100644
--- a/m4/evas_check_engine.m4
+++ b/m4/evas_check_engine.m4
@@ -419,10 +419,10 @@ have_dep="no"
419evas_engine_[]$1[]_cflags="" 419evas_engine_[]$1[]_cflags=""
420evas_engine_[]$1[]_libs="" 420evas_engine_[]$1[]_libs=""
421 421
422PKG_CHECK_EXISTS([sdl >= 1.2.0], 422PKG_CHECK_EXISTS([sdl2 >= 2.0.0],
423 [ 423 [
424 have_dep="yes" 424 have_dep="yes"
425 requirement="sdl >= 1.2.0" 425 requirement="sdl2 >= 2.0.0"
426 ], 426 ],
427 [have_dep="no"]) 427 [have_dep="no"])
428 428
diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am
index 1687444d68..c2c2f49126 100644
--- a/src/Makefile_Evas.am
+++ b/src/Makefile_Evas.am
@@ -949,17 +949,11 @@ modules_evas_engines_gl_sdl_module_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
949-I$(top_srcdir)/src/modules/evas/engines/gl_common \ 949-I$(top_srcdir)/src/modules/evas/engines/gl_common \
950@EVAS_CFLAGS@ \ 950@EVAS_CFLAGS@ \
951@evas_engine_gl_sdl_cflags@ 951@evas_engine_gl_sdl_cflags@
952modules_evas_engines_gl_sdl_module_la_LIBADD = 952modules_evas_engines_gl_sdl_module_la_LIBADD = \
953if ! EVAS_STATIC_BUILD_GL_COMMON
954modules_evas_engines_gl_sdl_module_la_LIBADD += \
955modules/evas/engines/gl_common/libevas_engine_gl_common.la
956endif
957modules_evas_engines_gl_sdl_module_la_LIBADD += \
958@USE_EVAS_LIBS@ \ 953@USE_EVAS_LIBS@ \
959@evas_engine_gl_sdl_libs@ 954@evas_engine_gl_sdl_libs@
960modules_evas_engines_gl_sdl_module_la_DEPENDENCIES = \ 955modules_evas_engines_gl_sdl_module_la_DEPENDENCIES = \
961@USE_EVAS_INTERNAL_LIBS@ \ 956@USE_EVAS_INTERNAL_LIBS@
962modules/evas/engines/gl_common/libevas_engine_gl_common.la
963modules_evas_engines_gl_sdl_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@ 957modules_evas_engines_gl_sdl_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@
964modules_evas_engines_gl_sdl_module_la_LIBTOOLFLAGS = --tag=disable-static 958modules_evas_engines_gl_sdl_module_la_LIBTOOLFLAGS = --tag=disable-static
965endif 959endif
diff --git a/src/lib/ecore_sdl/Ecore_Sdl.h b/src/lib/ecore_sdl/Ecore_Sdl.h
index 359e974718..ed4bd0f0a9 100644
--- a/src/lib/ecore_sdl/Ecore_Sdl.h
+++ b/src/lib/ecore_sdl/Ecore_Sdl.h
@@ -41,6 +41,26 @@ EAPI extern int ECORE_SDL_EVENT_LOST_FOCUS;
41EAPI extern int ECORE_SDL_EVENT_RESIZE; 41EAPI extern int ECORE_SDL_EVENT_RESIZE;
42EAPI extern int ECORE_SDL_EVENT_EXPOSE; 42EAPI extern int ECORE_SDL_EVENT_EXPOSE;
43 43
44typedef struct _Ecore_Sdl_Event_Video_Resize Ecore_Sdl_Event_Video_Resize;
45struct _Ecore_Sdl_Event_Video_Resize
46{
47 unsigned int windowID;
48 int w;
49 int h;
50};
51
52typedef struct _Ecore_Sdl_Event_Window Ecore_Sdl_Event_Window;
53struct _Ecore_Sdl_Event_Window
54{
55 unsigned int windowID;
56};
57
58EAPI int ecore_sdl_init(const char *name);
59EAPI int ecore_sdl_shutdown(void);
60EAPI void ecore_sdl_feed_events(void);
61
62 /* The following data structure have been deprecated since a long time */
63
44typedef struct _Ecore_Sdl_Event_Key_Down Ecore_Sdl_Event_Key_Down; 64typedef struct _Ecore_Sdl_Event_Key_Down Ecore_Sdl_Event_Key_Down;
45struct _Ecore_Sdl_Event_Key_Down /** SDL Key Down event */ 65struct _Ecore_Sdl_Event_Key_Down /** SDL Key Down event */
46{ 66{
@@ -96,17 +116,6 @@ struct _Ecore_Sdl_Event_Mouse_Wheel /** SDL Mouse Wheel event */
96 unsigned int time; 116 unsigned int time;
97}; 117};
98 118
99typedef struct _Ecore_Sdl_Event_Video_Resize Ecore_Sdl_Event_Video_Resize;
100struct _Ecore_Sdl_Event_Video_Resize
101{
102 int w;
103 int h;
104};
105
106EAPI int ecore_sdl_init(const char *name);
107EAPI int ecore_sdl_shutdown(void);
108EAPI void ecore_sdl_feed_events(void);
109
110#ifdef __cplusplus 119#ifdef __cplusplus
111} 120}
112#endif 121#endif
diff --git a/src/lib/ecore_sdl/Ecore_Sdl_Keys.h b/src/lib/ecore_sdl/Ecore_Sdl_Keys.h
index 4e298d77ea..2ca2069901 100644
--- a/src/lib/ecore_sdl/Ecore_Sdl_Keys.h
+++ b/src/lib/ecore_sdl/Ecore_Sdl_Keys.h
@@ -3,7 +3,7 @@
3 3
4struct _ecore_sdl_keys_s 4struct _ecore_sdl_keys_s
5{ 5{
6 unsigned int code; 6 SDL_Keycode code;
7 const char* name; 7 const char* name;
8 const char* compose; 8 const char* compose;
9}; 9};
@@ -11,9 +11,6 @@ struct _ecore_sdl_keys_s
11static const struct _ecore_sdl_keys_s keystable[] = 11static const struct _ecore_sdl_keys_s keystable[] =
12{ 12{
13 { SDLK_UNKNOWN, "0x00", "" }, 13 { SDLK_UNKNOWN, "0x00", "" },
14#ifndef BUILD_ECORE_EVAS_SDL_130
15 { SDLK_FIRST, "First", "First" },
16#endif
17 { SDLK_BACKSPACE, "BackSpace", "\010" }, 14 { SDLK_BACKSPACE, "BackSpace", "\010" },
18 { SDLK_TAB, "Tab", "\011" }, 15 { SDLK_TAB, "Tab", "\011" },
19 { SDLK_CLEAR, "Clear", "Clear" }, 16 { SDLK_CLEAR, "Clear", "Clear" },
@@ -89,116 +86,17 @@ static const struct _ecore_sdl_keys_s keystable[] =
89 { SDLK_DELETE, "Delete", "\177" }, 86 { SDLK_DELETE, "Delete", "\177" },
90 /* End of ASCII mapped keysyms */ 87 /* End of ASCII mapped keysyms */
91 88
92#ifndef BUILD_ECORE_EVAS_SDL_130
93 /* International keyboard syms */
94 { SDLK_WORLD_0, "w0", "" }, /* 0xA0 */
95 { SDLK_WORLD_1, "w1", "" },
96 { SDLK_WORLD_2, "w2", "" },
97 { SDLK_WORLD_3, "w3", "" },
98 { SDLK_WORLD_4, "w4", "" },
99 { SDLK_WORLD_5, "w5", "" },
100 { SDLK_WORLD_6, "w6", "" },
101 { SDLK_WORLD_7, "w7", "" },
102 { SDLK_WORLD_8, "w8", "" },
103 { SDLK_WORLD_9, "w9", "" },
104 { SDLK_WORLD_10, "w10", "" },
105 { SDLK_WORLD_11, "w11", "" },
106 { SDLK_WORLD_12, "w12", "" },
107 { SDLK_WORLD_13, "w13", "" },
108 { SDLK_WORLD_14, "w14", "" },
109 { SDLK_WORLD_15, "w15", "" },
110 { SDLK_WORLD_16, "w16", "" },
111 { SDLK_WORLD_17, "w17", "" },
112 { SDLK_WORLD_18, "w18", "" },
113 { SDLK_WORLD_19, "w19", "" },
114 { SDLK_WORLD_20, "w20", "" },
115 { SDLK_WORLD_21, "w21", "" },
116 { SDLK_WORLD_22, "w22", "" },
117 { SDLK_WORLD_23, "w23", "" },
118 { SDLK_WORLD_24, "w24", "" },
119 { SDLK_WORLD_25, "w25", "" },
120 { SDLK_WORLD_26, "w26", "" },
121 { SDLK_WORLD_27, "w27", "" },
122 { SDLK_WORLD_28, "w28", "" },
123 { SDLK_WORLD_29, "w29", "" },
124 { SDLK_WORLD_30, "w30", "" },
125 { SDLK_WORLD_31, "w31", "" },
126 { SDLK_WORLD_32, "w32", "" },
127 { SDLK_WORLD_33, "w33", "" },
128 { SDLK_WORLD_34, "w34", "" },
129 { SDLK_WORLD_35, "w35", "" },
130 { SDLK_WORLD_36, "w36", "" },
131 { SDLK_WORLD_37, "w37", "" },
132 { SDLK_WORLD_38, "w38", "" },
133 { SDLK_WORLD_39, "w39", "" },
134 { SDLK_WORLD_40, "w40", "" },
135 { SDLK_WORLD_41, "w41", "" },
136 { SDLK_WORLD_42, "w42", "" },
137 { SDLK_WORLD_43, "w43", "" },
138 { SDLK_WORLD_44, "w44", "" },
139 { SDLK_WORLD_45, "w45", "" },
140 { SDLK_WORLD_46, "w46", "" },
141 { SDLK_WORLD_47, "w47", "" },
142 { SDLK_WORLD_48, "w48", "" },
143 { SDLK_WORLD_49, "w49", "" },
144 { SDLK_WORLD_50, "w50", "" },
145 { SDLK_WORLD_51, "w51", "" },
146 { SDLK_WORLD_52, "w52", "" },
147 { SDLK_WORLD_53, "w53", "" },
148 { SDLK_WORLD_54, "w54", "" },
149 { SDLK_WORLD_55, "w55", "" },
150 { SDLK_WORLD_56, "w56", "" },
151 { SDLK_WORLD_57, "w57", "" },
152 { SDLK_WORLD_58, "w58", "" },
153 { SDLK_WORLD_59, "w59", "" },
154 { SDLK_WORLD_60, "w60", "" },
155 { SDLK_WORLD_61, "w61", "" },
156 { SDLK_WORLD_62, "w62", "" },
157 { SDLK_WORLD_63, "w63", "" },
158 { SDLK_WORLD_64, "w64", "" },
159 { SDLK_WORLD_65, "w65", "" },
160 { SDLK_WORLD_66, "w66", "" },
161 { SDLK_WORLD_67, "w67", "" },
162 { SDLK_WORLD_68, "w68", "" },
163 { SDLK_WORLD_69, "w69", "" },
164 { SDLK_WORLD_70, "w70", "" },
165 { SDLK_WORLD_71, "w71", "" },
166 { SDLK_WORLD_72, "w72", "" },
167 { SDLK_WORLD_73, "w73", "" },
168 { SDLK_WORLD_74, "w74", "" },
169 { SDLK_WORLD_75, "w75", "" },
170 { SDLK_WORLD_76, "w76", "" },
171 { SDLK_WORLD_77, "w77", "" },
172 { SDLK_WORLD_78, "w78", "" },
173 { SDLK_WORLD_79, "w79", "" },
174 { SDLK_WORLD_80, "w80", "" },
175 { SDLK_WORLD_81, "w81", "" },
176 { SDLK_WORLD_82, "w82", "" },
177 { SDLK_WORLD_83, "w83", "" },
178 { SDLK_WORLD_84, "w84", "" },
179 { SDLK_WORLD_85, "w85", "" },
180 { SDLK_WORLD_86, "w86", "" },
181 { SDLK_WORLD_87, "w87", "" },
182 { SDLK_WORLD_88, "w88", "" },
183 { SDLK_WORLD_89, "w89", "" },
184 { SDLK_WORLD_90, "w90", "" },
185 { SDLK_WORLD_91, "w91", "" },
186 { SDLK_WORLD_92, "w92", "" },
187 { SDLK_WORLD_93, "w93", "" },
188 { SDLK_WORLD_94, "w94", "" },
189 { SDLK_WORLD_95, "w95", "" },
190#endif
191 /* Numeric keypad */ 89 /* Numeric keypad */
192 { SDLK_KP0, "KP0", "0" }, 90 { SDLK_KP_0, "KP0", "0" },
193 { SDLK_KP1, "KP1", "1" }, 91 { SDLK_KP_1, "KP1", "1" },
194 { SDLK_KP2, "KP2", "2" }, 92 { SDLK_KP_2, "KP2", "2" },
195 { SDLK_KP3, "KP3", "3" }, 93 { SDLK_KP_3, "KP3", "3" },
196 { SDLK_KP4, "KP4", "4" }, 94 { SDLK_KP_4, "KP4", "4" },
197 { SDLK_KP5, "KP5", "5" }, 95 { SDLK_KP_5, "KP5", "5" },
198 { SDLK_KP6, "KP6", "6" }, 96 { SDLK_KP_6, "KP6", "6" },
199 { SDLK_KP7, "KP7", "7" }, 97 { SDLK_KP_7, "KP7", "7" },
200 { SDLK_KP8, "KP8", "8" }, 98 { SDLK_KP_8, "KP8", "8" },
201 { SDLK_KP9, "KP9", "9" }, 99 { SDLK_KP_9, "KP9", "9" },
202 { SDLK_KP_PERIOD, "period", "." }, 100 { SDLK_KP_PERIOD, "period", "." },
203 { SDLK_KP_DIVIDE, "KP_Divide", "/" }, 101 { SDLK_KP_DIVIDE, "KP_Divide", "/" },
204 { SDLK_KP_MULTIPLY, "KP_Multiply", "*" }, 102 { SDLK_KP_MULTIPLY, "KP_Multiply", "*" },
@@ -236,30 +134,25 @@ static const struct _ecore_sdl_keys_s keystable[] =
236 { SDLK_F15, "F15", "F15" }, 134 { SDLK_F15, "F15", "F15" },
237 135
238 /* Key state modifier keys */ 136 /* Key state modifier keys */
239 { SDLK_NUMLOCK, "Num_Lock", "Num_Lock" }, 137 { SDLK_NUMLOCKCLEAR, "Num_Lock", "Num_Lock" },
240 { SDLK_CAPSLOCK, "Caps_Lock", "Caps_Lock" }, 138 { SDLK_CAPSLOCK, "Caps_Lock", "Caps_Lock" },
241 { SDLK_SCROLLOCK, "Scroll_Lock", "Scroll_Lock" }, 139 { SDLK_SCROLLLOCK, "Scroll_Lock", "Scroll_Lock" },
242 { SDLK_RSHIFT, "Shift_R", "Shift_R" }, 140 { SDLK_RSHIFT, "Shift_R", "Shift_R" },
243 { SDLK_LSHIFT, "Shift_L", "Shift_L" }, 141 { SDLK_LSHIFT, "Shift_L", "Shift_L" },
244 { SDLK_RCTRL, "Control_R", "Control_R" }, 142 { SDLK_RCTRL, "Control_R", "Control_R" },
245 { SDLK_LCTRL, "Control_L", "Control_L" }, 143 { SDLK_LCTRL, "Control_L", "Control_L" },
246 { SDLK_RALT, "Alt_R", "Alt_R" }, 144 { SDLK_RALT, "Alt_R", "Alt_R" },
247 { SDLK_LALT, "Alt_L", "Alt_L" }, 145 { SDLK_LALT, "Alt_L", "Alt_L" },
248 { SDLK_RMETA, "Meta_R", "Meta_R" }, 146 { SDLK_LGUI, "Super_L", "Super_L" }, /* Left "Windows" key */
249 { SDLK_LMETA, "Meta_L", "Meta_L" }, 147 { SDLK_RGUI, "Super_R", "Super_R" }, /* Right "Windows" key */
250 { SDLK_LSUPER, "Super_L", "Super_L" }, /* Left "Windows" key */
251 { SDLK_RSUPER, "Super_R", "Super_R" }, /* Right "Windows" key */
252 { SDLK_MODE, "Mode", "Mode" }, /* "Alt Gr" key */ 148 { SDLK_MODE, "Mode", "Mode" }, /* "Alt Gr" key */
253 { SDLK_COMPOSE, "Compose", "Compose" }, /* Multi-key compose key */
254 149
255 /* Miscellaneous function keys */ 150 /* Miscellaneous function keys */
256 { SDLK_HELP, "Help", "Help" }, 151 { SDLK_HELP, "Help", "Help" },
257 { SDLK_PRINT, "Print", "Print" }, 152 { SDLK_PRINTSCREEN, "Print", "Print" },
258 { SDLK_SYSREQ, "SysReq", "SysReq" }, 153 { SDLK_SYSREQ, "SysReq", "SysReq" },
259 { SDLK_BREAK, "Break", "Break" },
260 { SDLK_MENU, "Menu", "Menu" }, 154 { SDLK_MENU, "Menu", "Menu" },
261 { SDLK_POWER, "Power", "Power" }, /* Power Macintosh power key */ 155 { SDLK_POWER, "Power", "Power" }, /* Power Macintosh power key */
262 { SDLK_EURO, "Euro", "\200" }, /* Some european keyboards */
263 { SDLK_UNDO, "Undo", "Undo" } /* Atari keyboard has Undo */ 156 { SDLK_UNDO, "Undo", "Undo" } /* Atari keyboard has Undo */
264}; 157};
265 158
diff --git a/src/lib/ecore_sdl/ecore_sdl.c b/src/lib/ecore_sdl/ecore_sdl.c
index ab85c75370..8b5897794b 100644
--- a/src/lib/ecore_sdl/ecore_sdl.c
+++ b/src/lib/ecore_sdl/ecore_sdl.c
@@ -2,7 +2,7 @@
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5#include <SDL/SDL.h> 5#include <SDL2/SDL.h>
6 6
7#include <Eina.h> 7#include <Eina.h>
8#include <Ecore.h> 8#include <Ecore.h>
@@ -19,7 +19,7 @@ struct _Ecore_SDL_Pressed
19{ 19{
20 EINA_RBTREE; 20 EINA_RBTREE;
21 21
22 SDLKey key; 22 SDL_Keycode key;
23}; 23};
24 24
25EAPI int ECORE_SDL_EVENT_GOT_FOCUS = 0; 25EAPI int ECORE_SDL_EVENT_GOT_FOCUS = 0;
@@ -40,7 +40,7 @@ _ecore_sdl_pressed_key(const Ecore_SDL_Pressed *left,
40 40
41static int 41static int
42_ecore_sdl_pressed_node(const Ecore_SDL_Pressed *node, 42_ecore_sdl_pressed_node(const Ecore_SDL_Pressed *node,
43 const SDLKey *key, 43 const SDL_Keycode *key,
44 EINA_UNUSED int length, 44 EINA_UNUSED int length,
45 EINA_UNUSED void *data) 45 EINA_UNUSED void *data)
46{ 46{
@@ -76,13 +76,13 @@ ecore_sdl_init(const char *name EINA_UNUSED)
76 if (!ecore_event_init()) 76 if (!ecore_event_init())
77 return --_ecore_sdl_init_count; 77 return --_ecore_sdl_init_count;
78 78
79 SDL_Init(SDL_INIT_EVENTS);
80
79 ECORE_SDL_EVENT_GOT_FOCUS = ecore_event_type_new(); 81 ECORE_SDL_EVENT_GOT_FOCUS = ecore_event_type_new();
80 ECORE_SDL_EVENT_LOST_FOCUS = ecore_event_type_new(); 82 ECORE_SDL_EVENT_LOST_FOCUS = ecore_event_type_new();
81 ECORE_SDL_EVENT_RESIZE = ecore_event_type_new(); 83 ECORE_SDL_EVENT_RESIZE = ecore_event_type_new();
82 ECORE_SDL_EVENT_EXPOSE = ecore_event_type_new(); 84 ECORE_SDL_EVENT_EXPOSE = ecore_event_type_new();
83 85
84 SDL_EnableKeyRepeat(200, 100);
85
86 return _ecore_sdl_init_count; 86 return _ecore_sdl_init_count;
87} 87}
88 88
@@ -98,6 +98,8 @@ ecore_sdl_shutdown(void)
98 if (--_ecore_sdl_init_count != 0) 98 if (--_ecore_sdl_init_count != 0)
99 return _ecore_sdl_init_count; 99 return _ecore_sdl_init_count;
100 100
101 SDL_Quit();
102
101 ecore_event_shutdown(); 103 ecore_event_shutdown();
102 eina_log_domain_unregister(_ecore_sdl_log_dom); 104 eina_log_domain_unregister(_ecore_sdl_log_dom);
103 _ecore_sdl_log_dom = -1; 105 _ecore_sdl_log_dom = -1;
@@ -131,7 +133,7 @@ _ecore_sdl_event_key(SDL_Event *event, double timestamp)
131 if (!ev) return NULL; 133 if (!ev) return NULL;
132 134
133 ev->timestamp = timestamp; 135 ev->timestamp = timestamp;
134 ev->window = 0; 136 ev->window = event->key.windowID;
135 ev->event_window = 0; 137 ev->event_window = 0;
136 ev->modifiers = _ecore_sdl_event_modifiers(SDL_GetModState()); 138 ev->modifiers = _ecore_sdl_event_modifiers(SDL_GetModState());
137 ev->key = NULL; 139 ev->key = NULL;
@@ -169,8 +171,8 @@ ecore_sdl_feed_events(void)
169 if (!ev) return; 171 if (!ev) return;
170 172
171 ev->timestamp = timestamp; 173 ev->timestamp = timestamp;
172 ev->window = 0; 174 ev->window = event.motion.windowID;
173 ev->event_window = 0; 175 ev->event_window = event.motion.windowID;
174 ev->modifiers = 0; /* FIXME: keep modifier around. */ 176 ev->modifiers = 0; /* FIXME: keep modifier around. */
175 ev->x = event.motion.x; 177 ev->x = event.motion.x;
176 ev->y = event.motion.y; 178 ev->y = event.motion.y;
@@ -188,46 +190,44 @@ ecore_sdl_feed_events(void)
188 } 190 }
189 case SDL_MOUSEBUTTONDOWN: 191 case SDL_MOUSEBUTTONDOWN:
190 { 192 {
191 if (event.button.button == SDL_BUTTON_WHEELUP || 193 Ecore_Event_Mouse_Button *ev;
192 event.button.button == SDL_BUTTON_WHEELDOWN)
193 {
194 Ecore_Event_Mouse_Wheel *ev;
195 194
196 ev = malloc(sizeof(Ecore_Event_Mouse_Wheel)); 195 ev = malloc(sizeof(Ecore_Event_Mouse_Button));
197 if (!ev) return; 196 if (!ev) return;
198 197
199 ev->timestamp = timestamp; 198 ev->timestamp = timestamp;
200 ev->window = 0; 199 ev->window = event.button.windowID;
201 ev->event_window = 0; 200 ev->event_window = event.button.windowID;
202 ev->modifiers = 0; /* FIXME: keep modifier around. */ 201 ev->modifiers = 0; /* FIXME: keep modifier around. */
203 ev->direction = 0; 202 ev->buttons = event.button.button;
204 ev->z = event.button.button == SDL_BUTTON_WHEELDOWN ? -1 : 1; 203 ev->double_click = 0;
204 ev->triple_click = 0;
205 205
206 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL); 206 /* Must set multi touch device to 0 or it will get ignored */
207 } 207 ev->multi.device = 0;
208 else 208 ev->multi.radius = ev->multi.radius_x = ev->multi.radius_y = 0;
209 { 209 ev->multi.pressure = ev->multi.angle = 0;
210 Ecore_Event_Mouse_Button *ev; 210 ev->multi.x = ev->multi.y = ev->multi.root.x = ev->multi.root.y = 0;
211 211
212 ev = malloc(sizeof(Ecore_Event_Mouse_Button)); 212 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
213 if (!ev) return; 213 break;
214 214 }
215 ev->timestamp = timestamp; 215 case SDL_MOUSEWHEEL:
216 ev->window = 0; 216 {
217 ev->event_window = 0; 217 Ecore_Event_Mouse_Wheel *ev;
218 ev->modifiers = 0; /* FIXME: keep modifier around. */ 218
219 ev->buttons = event.button.button; 219 ev = malloc(sizeof(Ecore_Event_Mouse_Wheel));
220 ev->double_click = 0; 220 if (!ev) return;
221 ev->triple_click = 0; 221
222 222 ev->timestamp = timestamp;
223 /* Must set multi touch device to 0 or it will get ignored */ 223 ev->window = event.wheel.windowID;
224 ev->multi.device = 0; 224 ev->event_window = event.wheel.windowID;
225 ev->multi.radius = ev->multi.radius_x = ev->multi.radius_y = 0; 225 ev->modifiers = 0; /* FIXME: keep modifier around. */
226 ev->multi.pressure = ev->multi.angle = 0; 226 ev->direction = 0;
227 ev->multi.x = ev->multi.y = ev->multi.root.x = ev->multi.root.y = 0; 227 ev->z = event.wheel.x != 0 ? event.wheel.x : event.wheel.y;
228 228 ev->direction = event.wheel.x != 0 ? 0 : 1;
229 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL); 229
230 } 230 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
231 break; 231 break;
232 } 232 }
233 case SDL_MOUSEBUTTONUP: 233 case SDL_MOUSEBUTTONUP:
@@ -237,8 +237,8 @@ ecore_sdl_feed_events(void)
237 ev = malloc(sizeof(Ecore_Event_Mouse_Button)); 237 ev = malloc(sizeof(Ecore_Event_Mouse_Button));
238 if (!ev) return; 238 if (!ev) return;
239 ev->timestamp = timestamp; 239 ev->timestamp = timestamp;
240 ev->window = 0; 240 ev->window = event.button.windowID;
241 ev->event_window = 0; 241 ev->event_window = event.button.windowID;
242 ev->modifiers = 0; /* FIXME: keep modifier around. */ 242 ev->modifiers = 0; /* FIXME: keep modifier around. */
243 ev->buttons = event.button.button; 243 ev->buttons = event.button.button;
244 ev->double_click = 0; 244 ev->double_click = 0;
@@ -253,20 +253,6 @@ ecore_sdl_feed_events(void)
253 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL); 253 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
254 break; 254 break;
255 } 255 }
256 case SDL_VIDEORESIZE:
257 {
258 Ecore_Sdl_Event_Video_Resize *ev;
259
260 ev = malloc(sizeof (Ecore_Sdl_Event_Video_Resize));
261 ev->w = event.resize.w;
262 ev->h = event.resize.h;
263
264 ecore_event_add(ECORE_SDL_EVENT_RESIZE, ev, NULL, NULL);
265 break;
266 }
267 case SDL_VIDEOEXPOSE:
268 ecore_event_add(ECORE_SDL_EVENT_EXPOSE, NULL, NULL, NULL);
269 break;
270 case SDL_QUIT: 256 case SDL_QUIT:
271 ecore_main_loop_quit(); 257 ecore_main_loop_quit();
272 break; 258 break;
@@ -317,8 +303,59 @@ ecore_sdl_feed_events(void)
317 if (ev) ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL); 303 if (ev) ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL);
318 break; 304 break;
319 } 305 }
320 case SDL_ACTIVEEVENT: 306 case SDL_WINDOWEVENT:
321 /* FIXME: Focus gain. */ 307 switch (event.window.event)
308 {
309 case SDL_WINDOWEVENT_RESIZED:
310 {
311 Ecore_Sdl_Event_Video_Resize *ev;
312
313 ev = calloc(1, sizeof (Ecore_Sdl_Event_Video_Resize));
314 ev->windowID = event.window.windowID;
315 ev->w = event.window.data1;
316 ev->h = event.window.data2;
317
318 ecore_event_add(ECORE_SDL_EVENT_RESIZE, ev, NULL, NULL);
319 break;
320 }
321 case SDL_WINDOWEVENT_EXPOSED:
322 {
323 Ecore_Sdl_Event_Window *ev;
324
325 ev = calloc(1, sizeof (Ecore_Sdl_Event_Window));
326 ev->windowID = event.window.windowID;
327
328 ecore_event_add(ECORE_SDL_EVENT_EXPOSE, ev, NULL, NULL);
329 break;
330 }
331 case SDL_WINDOWEVENT_ENTER:
332 case SDL_WINDOWEVENT_LEAVE:
333 {
334 Ecore_Event_Mouse_IO *ev;
335
336 ev = calloc(1, sizeof (Ecore_Event_Mouse_IO));
337 ev->window = event.window.windowID;
338 ev->event_window = event.window.windowID;
339
340 ecore_event_add(event.window.event == SDL_WINDOWEVENT_ENTER ?
341 ECORE_EVENT_MOUSE_IN : ECORE_EVENT_MOUSE_OUT,
342 ev, NULL, NULL);
343 break;
344 }
345 case SDL_WINDOWEVENT_FOCUS_GAINED:
346 case SDL_WINDOWEVENT_FOCUS_LOST:
347 {
348 Ecore_Sdl_Event_Window *ev;
349
350 ev = calloc(1, sizeof (Ecore_Sdl_Event_Window));
351 ev->windowID = event.window.windowID;
352
353 ecore_event_add(event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED ?
354 ECORE_SDL_EVENT_GOT_FOCUS : ECORE_SDL_EVENT_LOST_FOCUS,
355 ev, NULL, NULL);
356 break;
357 }
358 }
322 break; 359 break;
323 case SDL_SYSWMEVENT: 360 case SDL_SYSWMEVENT:
324 case SDL_USEREVENT: 361 case SDL_USEREVENT:
diff --git a/src/modules/ecore_evas/engines/sdl/ecore_evas_sdl.c b/src/modules/ecore_evas/engines/sdl/ecore_evas_sdl.c
index dcfa6cf373..218eab0f06 100644
--- a/src/modules/ecore_evas/engines/sdl/ecore_evas_sdl.c
+++ b/src/modules/ecore_evas/engines/sdl/ecore_evas_sdl.c
@@ -5,7 +5,7 @@
5#include <stdlib.h> 5#include <stdlib.h>
6#include <string.h> 6#include <string.h>
7 7
8#include <SDL/SDL.h> 8#include <SDL2/SDL.h>
9 9
10#include <Ecore.h> 10#include <Ecore.h>
11#include "ecore_private.h" 11#include "ecore_private.h"
@@ -27,9 +27,18 @@
27/* static char *ecore_evas_default_display = "0"; */ 27/* static char *ecore_evas_default_display = "0"; */
28/* static Ecore_List *ecore_evas_input_devices = NULL; */ 28/* static Ecore_List *ecore_evas_input_devices = NULL; */
29 29
30typedef struct _Ecore_Evas_SDL_Switch_Data Ecore_Evas_SDL_Switch_Data;
31struct _Ecore_Evas_SDL_Switch_Data
32{
33 SDL_Texture *pages[2];
34 SDL_Renderer *r;
35 SDL_Window *w;
36
37 unsigned char current;
38};
39
30static int _ecore_evas_init_count = 0; 40static int _ecore_evas_init_count = 0;
31 41
32static Ecore_Evas *sdl_ee = NULL;
33static Ecore_Event_Handler *ecore_evas_event_handlers[4] = { 42static Ecore_Event_Handler *ecore_evas_event_handlers[4] = {
34 NULL, NULL, NULL, NULL 43 NULL, NULL, NULL, NULL
35}; 44};
@@ -40,24 +49,38 @@ static int _ecore_evas_fps_debug = 0;
40static int ecore_evas_sdl_count = 0; 49static int ecore_evas_sdl_count = 0;
41 50
42static Ecore_Evas * 51static Ecore_Evas *
43_ecore_evas_sdl_match(void) 52_ecore_evas_sdl_match(unsigned int windowID)
44{ 53{
45 return sdl_ee; 54 return SDL_GetWindowData(SDL_GetWindowFromID(windowID), "_Ecore_Evas");
46} 55}
47 56
48static void * 57static void *
49_ecore_evas_sdl_switch_buffer(void *data, void *dest EINA_UNUSED) 58_ecore_evas_sdl_switch_buffer(void *data, void *dest EINA_UNUSED)
50{ 59{
51 SDL_Flip(data); 60 Ecore_Evas_SDL_Switch_Data *swd = data;
52 return ((SDL_Surface*)data)->pixels; 61 void *pixels;
62 int pitch;
63
64 /* Push current buffer to screen */
65 SDL_UnlockTexture(swd->pages[swd->current]);
66 SDL_RenderCopy(swd->r, swd->pages[swd->current], NULL, NULL);
67 SDL_RenderPresent(swd->r);
68
69 /* Switch to next buffer for rendering */
70 swd->current = (swd->current + 1) % 2;
71 if (SDL_LockTexture(swd->pages[swd->current], NULL, &pixels, &pitch) < 0)
72 return NULL;
73
74 return pixels;
53} 75}
54 76
55static Eina_Bool 77static Eina_Bool
56_ecore_evas_sdl_event_got_focus(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED) 78_ecore_evas_sdl_event_got_focus(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
57{ 79{
58 Ecore_Evas *ee; 80 Ecore_Sdl_Event_Window *ev = event;
81 Ecore_Evas *ee;
59 82
60 ee = _ecore_evas_sdl_match(); 83 ee = _ecore_evas_sdl_match(ev->windowID);
61 84
62 if (!ee) return ECORE_CALLBACK_PASS_ON; 85 if (!ee) return ECORE_CALLBACK_PASS_ON;
63 /* pass on event */ 86 /* pass on event */
@@ -70,9 +93,10 @@ _ecore_evas_sdl_event_got_focus(void *data EINA_UNUSED, int type EINA_UNUSED, vo
70static Eina_Bool 93static Eina_Bool
71_ecore_evas_sdl_event_lost_focus(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED) 94_ecore_evas_sdl_event_lost_focus(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
72{ 95{
73 Ecore_Evas *ee; 96 Ecore_Sdl_Event_Window *ev = event;
97 Ecore_Evas *ee;
74 98
75 ee = _ecore_evas_sdl_match(); 99 ee = _ecore_evas_sdl_match(ev->windowID);
76 100
77 if (!ee) return ECORE_CALLBACK_PASS_ON; 101 if (!ee) return ECORE_CALLBACK_PASS_ON;
78 /* pass on event */ 102 /* pass on event */
@@ -86,11 +110,11 @@ static Eina_Bool
86_ecore_evas_sdl_event_video_resize(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) 110_ecore_evas_sdl_event_video_resize(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
87{ 111{
88 Ecore_Sdl_Event_Video_Resize *e; 112 Ecore_Sdl_Event_Video_Resize *e;
89 Ecore_Evas *ee; 113 Ecore_Evas *ee;
90 int rmethod; 114 int rmethod;
91 115
92 e = event; 116 e = event;
93 ee = _ecore_evas_sdl_match(); 117 ee = _ecore_evas_sdl_match(e->windowID);
94 118
95 if (!ee) return ECORE_CALLBACK_PASS_ON; /* pass on event */ 119 if (!ee) return ECORE_CALLBACK_PASS_ON; /* pass on event */
96 120
@@ -102,22 +126,26 @@ _ecore_evas_sdl_event_video_resize(void *data EINA_UNUSED, int type EINA_UNUSED,
102 einfo = (Evas_Engine_Info_Buffer *) evas_engine_info_get(ee->evas); 126 einfo = (Evas_Engine_Info_Buffer *) evas_engine_info_get(ee->evas);
103 if (einfo) 127 if (einfo)
104 { 128 {
105 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_RGB32; 129 Ecore_Evas_SDL_Switch_Data *swd = (Ecore_Evas_SDL_Switch_Data*)(ee + 1);
106 einfo->info.switch_data = SDL_SetVideoMode(e->w, e->h, 32, 130 void *pixels;
107 (ee->prop.hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE) 131 int pitch;
108 | (ee->prop.fullscreen ? SDL_FULLSCREEN : 0) 132
109 | (ee->alpha ? SDL_SRCALPHA : 0) 133 SDL_UnlockTexture(swd->pages[swd->current]);
110 | SDL_DOUBLEBUF);
111 if (!einfo->info.switch_data)
112 {
113 return EINA_FALSE;
114 }
115 134
116 SDL_SetAlpha(einfo->info.switch_data, SDL_SRCALPHA, 0); 135 SDL_DestroyTexture(swd->pages[0]);
117 SDL_FillRect(einfo->info.switch_data, NULL, 0); 136 SDL_DestroyTexture(swd->pages[1]);
118 137
119 einfo->info.dest_buffer = ((SDL_Surface*)einfo->info.switch_data)->pixels; 138 SDL_RenderClear(swd->r);
120 einfo->info.dest_buffer_row_bytes = e->w * sizeof (int); 139
140 swd->pages[0] = SDL_CreateTexture(swd->r, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, e->w, e->h);
141 swd->pages[1] = SDL_CreateTexture(swd->r, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, e->w, e->h);
142
143 SDL_LockTexture(swd->pages[swd->current], NULL, &pixels, &pitch);
144
145 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_RGB32;
146 einfo->info.switch_data = swd;
147 einfo->info.dest_buffer = pixels;
148 einfo->info.dest_buffer_row_bytes = pitch;
121 einfo->info.use_color_key = 0; 149 einfo->info.use_color_key = 0;
122 einfo->info.alpha_threshold = 0; 150 einfo->info.alpha_threshold = 0;
123 einfo->info.func.new_update_region = NULL; 151 einfo->info.func.new_update_region = NULL;
@@ -142,13 +170,14 @@ _ecore_evas_sdl_event_video_resize(void *data EINA_UNUSED, int type EINA_UNUSED,
142} 170}
143 171
144static Eina_Bool 172static Eina_Bool
145_ecore_evas_sdl_event_video_expose(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED) 173_ecore_evas_sdl_event_video_expose(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
146{ 174{
147 Ecore_Evas *ee; 175 Ecore_Sdl_Event_Window *ev = event;
148 int w; 176 Ecore_Evas *ee;
149 int h; 177 int w;
178 int h;
150 179
151 ee = _ecore_evas_sdl_match(); 180 ee = _ecore_evas_sdl_match(ev->windowID);
152 181
153 if (!ee) return ECORE_CALLBACK_PASS_ON; 182 if (!ee) return ECORE_CALLBACK_PASS_ON;
154 evas_output_size_get(ee->evas, &w, &h); 183 evas_output_size_get(ee->evas, &w, &h);
@@ -260,12 +289,27 @@ _ecore_evas_sdl_shutdown(void)
260static void 289static void
261_ecore_evas_sdl_free(Ecore_Evas *ee) 290_ecore_evas_sdl_free(Ecore_Evas *ee)
262{ 291{
263 if (sdl_ee == ee) sdl_ee = NULL; 292 Ecore_Evas_SDL_Switch_Data *swd = (Ecore_Evas_SDL_Switch_Data*) (ee + 1);
293
294 ecore_event_window_unregister(SDL_GetWindowID(swd->w));
295
296 if (swd->pages[swd->current])
297 SDL_UnlockTexture(swd->pages[swd->current]);
298
299 if (swd->pages[0])
300 SDL_DestroyTexture(swd->pages[0]);
301 if (swd->pages[1])
302 SDL_DestroyTexture(swd->pages[1]);
303 if (swd->r)
304 SDL_DestroyRenderer(swd->r);
305 if (swd->w)
306 SDL_DestroyWindow(swd->w);
264 307
265 ecore_event_window_unregister(0);
266 _ecore_evas_sdl_shutdown(); 308 _ecore_evas_sdl_shutdown();
267 ecore_sdl_shutdown(); 309 ecore_sdl_shutdown();
268 ecore_evas_sdl_count--; 310 ecore_evas_sdl_count--;
311
312 SDL_VideoQuit();
269} 313}
270 314
271static void 315static void
@@ -287,22 +331,26 @@ _ecore_evas_resize(Ecore_Evas *ee, int w, int h)
287 einfo = (Evas_Engine_Info_Buffer *) evas_engine_info_get(ee->evas); 331 einfo = (Evas_Engine_Info_Buffer *) evas_engine_info_get(ee->evas);
288 if (einfo) 332 if (einfo)
289 { 333 {
290 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_RGB32; 334 Ecore_Evas_SDL_Switch_Data *swd = (Ecore_Evas_SDL_Switch_Data*)(ee + 1);
291 einfo->info.switch_data = SDL_SetVideoMode(w, h, 32, 335 void *pixels;
292 (ee->prop.hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE) 336 int pitch;
293 | (ee->prop.fullscreen ? SDL_FULLSCREEN : 0) 337
294 | (ee->alpha ? SDL_SRCALPHA : 0) 338 SDL_UnlockTexture(swd->pages[swd->current]);
295 | SDL_DOUBLEBUF); 339
296 if (!einfo->info.switch_data) 340 SDL_DestroyTexture(swd->pages[0]);
297 { 341 SDL_DestroyTexture(swd->pages[1]);
298 return; 342
299 } 343 SDL_RenderClear(swd->r);
300 344
301 SDL_SetAlpha(einfo->info.switch_data, SDL_SRCALPHA, 0); 345 swd->pages[0] = SDL_CreateTexture(swd->r, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, w, h);
302 SDL_FillRect(einfo->info.switch_data, NULL, 0); 346 swd->pages[1] = SDL_CreateTexture(swd->r, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, w, h);
303 347
304 einfo->info.dest_buffer = ((SDL_Surface*)einfo->info.switch_data)->pixels; 348 SDL_LockTexture(swd->pages[swd->current], NULL, &pixels, &pitch);
305 einfo->info.dest_buffer_row_bytes = w * sizeof (int); 349
350 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_RGB32;
351 einfo->info.switch_data = swd;
352 einfo->info.dest_buffer = pixels;
353 einfo->info.dest_buffer_row_bytes = pitch;
306 einfo->info.use_color_key = 0; 354 einfo->info.use_color_key = 0;
307 einfo->info.alpha_threshold = 0; 355 einfo->info.alpha_threshold = 0;
308 einfo->info.func.new_update_region = NULL; 356 einfo->info.func.new_update_region = NULL;
@@ -476,15 +524,27 @@ static Ecore_Evas_Engine_Func _ecore_sdl_engine_func =
476static Ecore_Evas* 524static Ecore_Evas*
477_ecore_evas_internal_sdl_new(int rmethod, const char* name, int w, int h, int fullscreen, int hwsurface, int noframe, int alpha) 525_ecore_evas_internal_sdl_new(int rmethod, const char* name, int w, int h, int fullscreen, int hwsurface, int noframe, int alpha)
478{ 526{
479 Ecore_Evas *ee; 527 Ecore_Evas_SDL_Switch_Data *swd;
528 Ecore_Evas *ee;
529 Eina_Bool gl = EINA_FALSE;
480 530
481 if (ecore_evas_sdl_count > 0) return NULL; 531 if (ecore_evas_sdl_count > 0) return NULL;
482 if (!name) 532 if (!name)
483 name = ecore_evas_sdl_default; 533 name = ecore_evas_sdl_default;
484 534
485 ee = calloc(1, sizeof(Ecore_Evas)); 535 if (!ecore_sdl_init(name)) return NULL;
536
537 if (SDL_VideoInit(NULL) != 0)
538 {
539 ERR("SDL Video initialization failed !");
540 return NULL;
541 }
542
543 ee = calloc(1, sizeof(Ecore_Evas) + sizeof (Ecore_Evas_SDL_Switch_Data));
486 if (!ee) return NULL; 544 if (!ee) return NULL;
487 545
546 swd = (Ecore_Evas_SDL_Switch_Data*)(ee + 1);
547
488 ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS); 548 ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
489 549
490 ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_sdl_engine_func; 550 ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_sdl_engine_func;
@@ -522,41 +582,51 @@ _ecore_evas_internal_sdl_new(int rmethod, const char* name, int w, int h, int fu
522 evas_output_size_set(ee->evas, w, h); 582 evas_output_size_set(ee->evas, w, h);
523 evas_output_viewport_set(ee->evas, 0, 0, w, h); 583 evas_output_viewport_set(ee->evas, 0, 0, w, h);
524 584
525 if (rmethod == evas_render_method_lookup("buffer")) 585 gl = !(rmethod == evas_render_method_lookup("buffer"));
586
587 swd->w = SDL_CreateWindow(name,
588 SDL_WINDOWPOS_UNDEFINED,
589 SDL_WINDOWPOS_UNDEFINED,
590 w, h,
591 SDL_WINDOW_RESIZABLE | (gl ? SDL_WINDOW_OPENGL : 0));
592 if (!swd->w)
593 {
594 ERR("SDL_CreateWindow failed.");
595 goto on_error;
596 }
597
598 if (!gl)
526 { 599 {
527 Evas_Engine_Info_Buffer *einfo; 600 Evas_Engine_Info_Buffer *einfo;
528 601
529 einfo = (Evas_Engine_Info_Buffer *) evas_engine_info_get(ee->evas); 602 einfo = (Evas_Engine_Info_Buffer *) evas_engine_info_get(ee->evas);
530 if (einfo) 603 if (einfo)
531 { 604 {
532 SDL_Init(SDL_INIT_NOPARACHUTE); 605 void *pixels;
606 int pitch;
533 607
534 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) 608 swd->r = SDL_CreateRenderer(swd->w, -1, 0);
609 if (!swd->r)
535 { 610 {
536 ERR("SDL_Init failed with %s", SDL_GetError()); 611 ERR("SDL_CreateRenderer failed.");
537 SDL_Quit(); 612 goto on_error;
538 return NULL;
539 } 613 }
540 614
615 swd->pages[0] = SDL_CreateTexture(swd->r, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, w, h);
616 swd->pages[1] = SDL_CreateTexture(swd->r, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, w, h);
617
541 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_RGB32; 618 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_RGB32;
542 einfo->info.switch_data = SDL_SetVideoMode(w, h, 32, 619 einfo->info.switch_data = swd;
543 (hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE) 620
544 | (fullscreen ? SDL_FULLSCREEN : 0) 621 SDL_RenderClear(swd->r);
545 | (noframe ? SDL_NOFRAME : 0) 622 if (SDL_LockTexture(swd->pages[0], NULL, &pixels, &pitch) < 0)
546 | (alpha ? SDL_SRCALPHA : 0)
547 | SDL_DOUBLEBUF);
548 if (!einfo->info.switch_data)
549 { 623 {
550 ERR("SDL_SetVideoMode failed !"); 624 ERR("SDL_LockTexture failed.");
551 ecore_evas_free(ee); 625 goto on_error;
552 return NULL;
553 } 626 }
554 627
555 SDL_SetAlpha(einfo->info.switch_data, SDL_SRCALPHA, 0); 628 einfo->info.dest_buffer = pixels;
556 SDL_FillRect(einfo->info.switch_data, NULL, 0); 629 einfo->info.dest_buffer_row_bytes = pitch;
557
558 einfo->info.dest_buffer = ((SDL_Surface*)einfo->info.switch_data)->pixels;
559 einfo->info.dest_buffer_row_bytes = w * sizeof (int);
560 einfo->info.use_color_key = 0; 630 einfo->info.use_color_key = 0;
561 einfo->info.alpha_threshold = 0; 631 einfo->info.alpha_threshold = 0;
562 einfo->info.func.new_update_region = NULL; 632 einfo->info.func.new_update_region = NULL;
@@ -576,8 +646,9 @@ _ecore_evas_internal_sdl_new(int rmethod, const char* name, int w, int h, int fu
576 return NULL; 646 return NULL;
577 } 647 }
578 } 648 }
579 else if (rmethod == evas_render_method_lookup("gl_sdl")) 649 else
580 { 650 {
651 /* FIXME */
581#ifdef BUILD_ECORE_EVAS_OPENGL_SDL 652#ifdef BUILD_ECORE_EVAS_OPENGL_SDL
582 Evas_Engine_Info_GL_SDL *einfo; 653 Evas_Engine_Info_GL_SDL *einfo;
583 654
@@ -586,6 +657,7 @@ _ecore_evas_internal_sdl_new(int rmethod, const char* name, int w, int h, int fu
586 { 657 {
587 einfo->flags.fullscreen = fullscreen; 658 einfo->flags.fullscreen = fullscreen;
588 einfo->flags.noframe = noframe; 659 einfo->flags.noframe = noframe;
660 einfo->window = swd->w;
589 if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo)) 661 if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
590 { 662 {
591 ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver); 663 ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver);
@@ -601,42 +673,32 @@ _ecore_evas_internal_sdl_new(int rmethod, const char* name, int w, int h, int fu
601 } 673 }
602#endif 674#endif
603 } 675 }
604 else
605 {
606 ERR("evas_engine_info_set() init engine '%s' failed.", ee->driver);
607 ecore_evas_free(ee);
608 return NULL;
609 }
610
611 if (!ecore_sdl_init(name))
612 {
613 evas_free(ee->evas);
614 if (ee->name) free(ee->name);
615 free(ee);
616 return NULL;
617 }
618 676
619 _ecore_evas_sdl_init(w, h); 677 _ecore_evas_sdl_init(w, h);
620 678
621 ecore_event_window_register(0, ee, ee->evas, 679 ecore_event_window_register(SDL_GetWindowID(swd->w), ee, ee->evas,
622 (Ecore_Event_Mouse_Move_Cb)_ecore_evas_mouse_move_process, 680 (Ecore_Event_Mouse_Move_Cb)_ecore_evas_mouse_move_process,
623 (Ecore_Event_Multi_Move_Cb)_ecore_evas_mouse_multi_move_process, 681 (Ecore_Event_Multi_Move_Cb)_ecore_evas_mouse_multi_move_process,
624 (Ecore_Event_Multi_Down_Cb)_ecore_evas_mouse_multi_down_process, 682 (Ecore_Event_Multi_Down_Cb)_ecore_evas_mouse_multi_down_process,
625 (Ecore_Event_Multi_Up_Cb)_ecore_evas_mouse_multi_up_process); 683 (Ecore_Event_Multi_Up_Cb)_ecore_evas_mouse_multi_up_process);
684 SDL_SetWindowData(swd->w, "_Ecore_Evas", ee);
626 685
627 SDL_ShowCursor(SDL_ENABLE); 686 SDL_ShowCursor(SDL_ENABLE);
628 687
629 ee->engine.func->fn_render = _ecore_evas_sdl_render; 688 ee->engine.func->fn_render = _ecore_evas_sdl_render;
630 _ecore_evas_register(ee); 689 _ecore_evas_register(ee);
631 690
632 sdl_ee = ee;
633 ecore_evas_sdl_count++; 691 ecore_evas_sdl_count++;
634 return ee; 692 return ee;
693
694 on_error:
695 ecore_evas_free(ee);
696 return NULL;
635} 697}
636 698
637EAPI Ecore_Evas * 699EAPI Ecore_Evas *
638ecore_evas_sdl_new_internal(const char* name, int w, int h, int fullscreen, 700ecore_evas_sdl_new_internal(const char* name, int w, int h, int fullscreen,
639 int hwsurface, int noframe, int alpha) 701 int hwsurface, int noframe, int alpha)
640{ 702{
641 Ecore_Evas *ee; 703 Ecore_Evas *ee;
642 int rmethod; 704 int rmethod;
@@ -670,4 +732,3 @@ ecore_evas_gl_sdl_new_internal(const char* name, int w, int h, int fullscreen, i
670 return ee; 732 return ee;
671} 733}
672#endif 734#endif
673
diff --git a/src/modules/evas/engines/gl_sdl/Evas_Engine_GL_SDL.h b/src/modules/evas/engines/gl_sdl/Evas_Engine_GL_SDL.h
index 3804aa06e5..de2370edd2 100644
--- a/src/modules/evas/engines/gl_sdl/Evas_Engine_GL_SDL.h
+++ b/src/modules/evas/engines/gl_sdl/Evas_Engine_GL_SDL.h
@@ -11,14 +11,13 @@ struct _Evas_Engine_Info_GL_SDL
11 /* at you and make nasty noises */ 11 /* at you and make nasty noises */
12 Evas_Engine_Info magic; 12 Evas_Engine_Info magic;
13 13
14 SDL_Window *window;
15
14 /* engine specific data & parameters it needs to set up */ 16 /* engine specific data & parameters it needs to set up */
15 struct { 17 struct {
16 int rotation; 18 int rotation;
17 int fullscreen : 1; 19 int fullscreen : 1;
18 int noframe : 1; 20 int noframe : 1;
19 } flags; 21 } flags;
20
21}; 22};
22#endif 23#endif
23
24
diff --git a/src/modules/evas/engines/gl_sdl/evas_engine.c b/src/modules/evas/engines/gl_sdl/evas_engine.c
index cfe6ade2ea..b0216f29eb 100644
--- a/src/modules/evas/engines/gl_sdl/evas_engine.c
+++ b/src/modules/evas/engines/gl_sdl/evas_engine.c
@@ -2,890 +2,391 @@
2#include "evas_private.h" 2#include "evas_private.h"
3#include "evas_engine.h" 3#include "evas_engine.h"
4 4
5static void* _sdl_output_setup (int w, int h, int fullscreen, int noframe); 5#include <dlfcn.h>
6 6
7#include <SDL2/SDL_opengl.h>
8
9Evas_GL_Common_Context_New glsym_evas_gl_common_context_new = NULL;
10Evas_GL_Common_Context_Call glsym_evas_gl_common_context_free = NULL;
11Evas_GL_Common_Context_Call glsym_evas_gl_common_context_use = NULL;
12Evas_GL_Common_Context_Call glsym_evas_gl_common_context_flush = NULL;
13Evas_GL_Common_Context_Call glsym_evas_gl_common_image_all_unload = NULL;
14Evas_GL_Common_Context_Resize_Call glsym_evas_gl_common_context_resize = NULL;
15Evas_GL_Preload_Render_Call glsym_evas_gl_preload_render_lock = NULL;
16Evas_Gl_Symbols glsym_evas_gl_symbols = NULL;
17
18static Outbuf *_sdl_output_setup(int w, int h, int fullscreen, int noframe, Evas_Engine_Info_GL_SDL *info);
19
7int _evas_engine_GL_SDL_log_dom = -1; 20int _evas_engine_GL_SDL_log_dom = -1;
8/* function tables - filled in later (func and parent func) */ 21/* function tables - filled in later (func and parent func) */
9static Evas_Func func, pfunc; 22static Evas_Func func, pfunc;
10 23
11static void * 24static void
12eng_info(Evas *e EINA_UNUSED) 25_outbuf_reconfigure(Outbuf *ob EINA_UNUSED, int w EINA_UNUSED, int h EINA_UNUSED, int rot EINA_UNUSED, Outbuf_Depth depth EINA_UNUSED)
13{ 26{
14 Evas_Engine_Info_GL_SDL *info;
15
16 info = calloc(1, sizeof(Evas_Engine_Info_GL_SDL));
17 if (!info) return NULL;
18 info->magic.magic = rand();
19 return info;
20} 27}
21 28
22static void 29static Eina_Bool
23eng_info_free(Evas *e EINA_UNUSED, void *info) 30_outbuf_region_first_rect(Outbuf *ob EINA_UNUSED)
24{ 31{
25 Evas_Engine_Info_GL_SDL *in; 32 return EINA_FALSE;
26 in = (Evas_Engine_Info_GL_SDL *)info;
27 free(in);
28} 33}
29 34
30static int 35static void *
31eng_setup(Evas *eo_e, void *in) 36_outbuf_new_region_for_update(Outbuf *ob,
37 int x EINA_UNUSED, int y EINA_UNUSED, int w EINA_UNUSED, int h EINA_UNUSED,
38 int *cx EINA_UNUSED, int *cy EINA_UNUSED, int *cw EINA_UNUSED, int *ch EINA_UNUSED)
32{ 39{
33 Evas_Public_Data *e = eo_data_scope_get(eo_e, EVAS_CANVAS_CLASS); 40 return ob->gl_context->def_surface;
34 Render_Engine *re;
35 Evas_Engine_Info_GL_SDL *info;
36
37 info = (Evas_Engine_Info_GL_SDL *)in;
38
39 SDL_Init(SDL_INIT_NOPARACHUTE);
40
41 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
42 {
43 ERR("SDL_Init failed with %s", SDL_GetError());
44 SDL_Quit();
45 return 0;
46 }
47
48 re = _sdl_output_setup(e->output.w, e->output.h,
49 info->flags.fullscreen,
50 info->flags.noframe);
51 re->info = info;
52 e->engine.data.output = re;
53 if (!e->engine.data.output)
54 return 0;
55
56 e->engine.func = &func;
57 e->engine.data.context = e->engine.func->context_new(e->engine.data.output);
58
59 return 1;
60} 41}
61 42
62static void 43static void
63eng_output_free(void *data) 44_outbuf_push_updated_region(Outbuf *ob EINA_UNUSED,
45 RGBA_Image *update EINA_UNUSED,
46 int x EINA_UNUSED, int y EINA_UNUSED, int w EINA_UNUSED, int h EINA_UNUSED)
64{ 47{
65 Render_Engine *re;
66
67 re = (Render_Engine *)data;
68
69 if (re)
70 {
71 evas_gl_common_context_free(re->gl_context);
72 free(re);
73
74 evas_common_font_shutdown();
75 evas_common_image_shutdown();
76
77 SDL_QuitSubSystem(SDL_INIT_VIDEO);
78 }
79} 48}
80 49
81static void 50static void
82eng_output_resize(void *data, int w, int h) 51_outbuf_free_region_for_update(Outbuf *ob EINA_UNUSED, RGBA_Image *update EINA_UNUSED)
83{ 52{
84 Render_Engine *re;
85 SDL_Surface *surface;
86
87 re = (Render_Engine *)data;
88 re->w = w;
89 re->h = h;
90
91 if(SDL_GetVideoSurface()->flags & SDL_RESIZABLE)
92 {
93 surface = SDL_SetVideoMode(w, h, 32, EVAS_SDL_GL_FLAG
94 | (re->info->flags.fullscreen ? SDL_FULLSCREEN : 0)
95 | (re->info->flags.noframe ? SDL_NOFRAME : 0));
96 if (!surface)
97 {
98 ERR("Unable to change the resolution to : %ix%i", w, h);
99 SDL_Quit();
100 exit(-1);
101 }
102 }
103
104 evas_gl_common_context_resize(re->gl_context, w, h, re->gl_context->rot);
105} 53}
106 54
107static void 55static void
108eng_output_tile_size_set(void *data EINA_UNUSED, int w EINA_UNUSED, int h EINA_UNUSED) 56_outbuf_free(Outbuf *ob)
109{ 57{
58 glsym_evas_gl_common_context_free(ob->gl_context);
110} 59}
111 60
112static void 61static int
113eng_output_redraws_rect_add(void *data, int x, int y, int w, int h) 62_outbuf_get_rot(Outbuf *ob EINA_UNUSED)
114{ 63{
115 Render_Engine *re; 64 return 0;
116
117 re = (Render_Engine *)data;
118 evas_gl_common_context_resize(re->gl_context, re->w, re->h, re->gl_context->rot);
119 /* smple bounding box */
120 if (!re->draw.redraw)
121 {
122#if 0
123 re->draw.x1 = x;
124 re->draw.y1 = y;
125 re->draw.x2 = x + w - 1;
126 re->draw.y2 = y + h - 1;
127#else
128 re->draw.x1 = 0;
129 re->draw.y1 = 0;
130 re->draw.x2 = re->w - 1;
131 re->draw.y2 = re->h - 1;
132#endif
133 }
134 else
135 {
136 if (x < re->draw.x1) re->draw.x1 = x;
137 if (y < re->draw.y1) re->draw.y1 = y;
138 if ((x + w - 1) > re->draw.x2) re->draw.x2 = x + w - 1;
139 if ((y + h - 1) > re->draw.y2) re->draw.y2 = y + h - 1;
140 }
141 re->draw.redraw = 1;
142} 65}
143 66
144static void 67static void
145eng_output_redraws_rect_del(void *data EINA_UNUSED, int x EINA_UNUSED, int y EINA_UNUSED, int w EINA_UNUSED, int h EINA_UNUSED) 68_outbuf_flush(Outbuf *ob, Tilebuf_Rect *rects EINA_UNUSED, Evas_Render_Mode render_mode EINA_UNUSED)
146{ 69{
70 SDL_GL_SwapWindow(ob->window);
147} 71}
148 72
149static void 73static Eina_Bool
150eng_output_redraws_clear(void *data) 74eng_window_make_current(void *data, void *doit EINA_UNUSED)
151{ 75{
152 Render_Engine *re; 76 Outbuf *ob = data;
153 77
154 re = (Render_Engine *)data; 78 SDL_GL_MakeCurrent(ob->window, ob->context);
155 re->draw.redraw = 0; 79 return EINA_TRUE;
156// INF("GL: finish update cycle!");
157} 80}
158 81
159/* at least the nvidia drivers are so abysmal that copying from the backbuffer 82static void
160 * to the front using glCopyPixels() that you literally can WATCH it draw the 83_window_use(Outbuf *ob)
161 * pixels slowly across the screen with a window update taking multiple
162 * seconds - so workaround by doing a full buffer render as frankly GL isn't
163 * up to doing anything that isn't done by quake (etc.)
164 */
165#define SLOW_GL_COPY_RECT 1
166/* vsync games - not for now though */
167//#define VSYNC_TO_SCREEN 1
168
169static void *
170eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
171{ 84{
172 Render_Engine *re; 85 /* With SDL 1.x, only one window, no issue here so only flush evas context */
86 glsym_evas_gl_preload_render_lock(eng_window_make_current, ob);
173 87
174 re = (Render_Engine *)data; 88 if (ob)
175 evas_gl_common_context_flush(re->gl_context);
176 evas_gl_common_context_newframe(re->gl_context);
177 /* get the upate rect surface - return engine data as dummy */
178 if (!re->draw.redraw)
179 { 89 {
180// printf("GL: NO updates!\n"); 90 glsym_evas_gl_common_context_use(ob->gl_context);
181 return NULL; 91 glsym_evas_gl_common_context_flush(ob->gl_context);
182 } 92 }
183// printf("GL: update....!\n");
184#ifdef SLOW_GL_COPY_RECT
185 /* if any update - just return the whole canvas - works with swap
186 * buffers then */
187 if (x) *x = 0;
188 if (y) *y = 0;
189 if (w) *w = re->w;
190 if (h) *h = re->h;
191 if (cx) *cx = 0;
192 if (cy) *cy = 0;
193 if (cw) *cw = re->w;
194 if (ch) *ch = re->h;
195#else
196 /* 1 update - INCREDIBLY SLOW if combined with swap_rect in flush. a gl
197 * problem where there just is no hardware path for somethnig that
198 * obviously SHOULD be there */
199 /* only 1 update to minimise gl context games and rendering multiple update
200 * regions as evas does with other engines
201 */
202 if (x) *x = re->draw.x1;
203 if (y) *y = re->draw.y1;
204 if (w) *w = re->draw.x2 - re->draw.x1 + 1;
205 if (h) *h = re->draw.y2 - re->draw.y1 + 1;
206 if (cx) *cx = re->draw.x1;
207 if (cy) *cy = re->draw.y1;
208 if (cw) *cw = re->draw.x2 - re->draw.x1 + 1;
209 if (ch) *ch = re->draw.y2 - re->draw.y1 + 1;
210#endif
211// clear buffer. only needed for dest alpha
212// glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
213// glClear(GL_COLOR_BUFFER_BIT);
214//x// printf("frame -> new\n");
215 return re->gl_context->def_surface;
216} 93}
217 94
218static void 95static Evas_Engine_GL_Context *
219eng_output_redraws_next_update_push(void *data, void *surface EINA_UNUSED, int x EINA_UNUSED, int y EINA_UNUSED, int w EINA_UNUSED, int h EINA_UNUSED, Evas_Render_Mode render_mode) 96_window_gl_context_get(Outbuf *ob)
220{ 97{
221 Render_Engine *re; 98 return ob->gl_context;
222
223 if (render_mode == EVAS_RENDER_MODE_ASYNC_INIT) return;
224
225 re = (Render_Engine *)data;
226 /* put back update surface.. in this case just unflag redraw */
227 re->draw.redraw = 0;
228 re->draw.drew = 1;
229 evas_gl_common_context_flush(re->gl_context);
230//x// printf("frame -> push\n");
231} 99}
232 100
233static void 101static void *
234eng_output_flush(void *data, Evas_Render_Mode render_mode) 102_window_egl_display_get(Outbuf *ob)
235{ 103{
236 Render_Engine *re;
237
238 if (render_mode == EVAS_RENDER_MODE_ASYNC_INIT) return;
239
240 re = (Render_Engine *)data;
241 if (!re->draw.drew) return;
242//x// printf("frame -> flush\n");
243 re->draw.drew = 0;
244
245#if 0
246#ifdef GL_GLES 104#ifdef GL_GLES
247// glFlush(); 105 return ob->egl_disp;
248 eglSwapBuffers(re->egl_disp, re->egl_surface[0]);
249#else 106#else
250 glXSwapBuffers(re->win->disp, re->win); 107 (void) ob;
251#endif 108 return NULL;
252#else
253 SDL_GL_SwapBuffers();
254#endif 109#endif
255} 110}
256 111
257static void 112struct _Context_3D
258eng_output_idle_flush(void *data EINA_UNUSED)
259{ 113{
260} 114 Outbuf *ob;
115 SDL_GLContext sdl_context;
116};
261 117
262static void 118static Context_3D *
263eng_output_dump(void *data) 119_window_gl_context_new(Outbuf *ob)
264{ 120{
265 Render_Engine *re; 121 Context_3D *ctx;
266 122
267 re = (Render_Engine *)data; 123 ctx = calloc(1, sizeof (Context_3D));
268 evas_common_image_image_all_unload(); 124 if (!ctx) return NULL;
269 evas_common_font_font_all_unload();
270 evas_gl_common_image_all_unload(re->gl_context);
271}
272 125
273static void 126 ctx->ob = ob;
274eng_context_cutout_add(void *data EINA_UNUSED, void *context, int x, int y, int w, int h) 127 ctx->sdl_context = SDL_GL_CreateContext(ob->window);
275{
276 evas_common_draw_context_add_cutout(context, x, y, w, h);
277}
278 128
279static void 129 return ctx;
280eng_context_cutout_clear(void *data EINA_UNUSED, void *context)
281{
282 evas_common_draw_context_clear_cutouts(context);
283} 130}
284 131
285static void 132static void
286eng_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h, Eina_Bool do_async EINA_UNUSED) 133_window_gl_context_use(Context_3D *ctx)
287{ 134{
288 Render_Engine *re; 135 SDL_GL_MakeCurrent(ctx->ob->window, ctx->sdl_context);
289
290 re = (Render_Engine *)data;
291 evas_gl_common_context_target_surface_set(re->gl_context, surface);
292 re->gl_context->dc = context;
293 evas_gl_common_rect_draw(re->gl_context, x, y, w, h);
294} 136}
295 137
296static void 138/* FIXME: noway to destroy Context_3D */
297eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2, Eina_Bool do_async EINA_UNUSED)
298{
299 Render_Engine *re;
300
301 re = (Render_Engine *)data;
302 evas_gl_common_context_target_surface_set(re->gl_context, surface);
303 re->gl_context->dc = context;
304 evas_gl_common_line_draw(re->gl_context, x1, y1, x2, y2);
305}
306 139
307static void * 140static void *
308eng_polygon_point_add(void *data EINA_UNUSED, void *context EINA_UNUSED, void *polygon, int x, int y) 141evgl_eng_display_get(void *data)
309{ 142{
310 return evas_gl_common_poly_point_add(polygon, x, y); 143 Render_Engine *re = data;
311}
312 144
313static void * 145 if (!re->generic.software.ob) return NULL;
314eng_polygon_points_clear(void *data EINA_UNUSED, void *context EINA_UNUSED, void *polygon) 146#ifdef GL_GLES
315{ 147 return re->generic.software.ob->egl_disp;
316 return evas_gl_common_poly_points_clear(polygon); 148#else
149 return NULL; /* FIXME: what should we do here ? */
150#endif
317} 151}
318 152
319static void 153static void *
320eng_polygon_draw(void *data, void *context, void *surface, void *polygon, int x, int y, Eina_Bool do_async EINA_UNUSED) 154evgl_eng_evas_surface_get(void *data)
321{ 155{
322 Render_Engine *re; 156 Render_Engine *re = data;
323 157
324 re = (Render_Engine *)data; 158 return re->generic.software.ob->window;
325 evas_gl_common_context_target_surface_set(re->gl_context, surface);
326 re->gl_context->dc = context;
327 evas_gl_common_poly_draw(re->gl_context, polygon, x, y);
328} 159}
329 160
330static int 161static int
331eng_image_alpha_get(void *data EINA_UNUSED, void *image) 162evgl_eng_make_current(void *data EINA_UNUSED,
163 void *surface, void *context,
164 int flush)
332{ 165{
333 Evas_GL_Image *im = image; 166 if (flush) _window_use(NULL);
334 167 SDL_GL_MakeCurrent(surface, context);
335 return im ? im->alpha : 1; 168 return EINA_TRUE;
336} 169}
337 170
338static Evas_Colorspace 171static void *
339eng_image_colorspace_get(void *data EINA_UNUSED, void *image) 172evgl_eng_native_window_create(void *data EINA_UNUSED)
340{ 173{
341 Evas_GL_Image *im = image; 174 /* FIXME: Need to understand how to implement that with SDL */
342 175 return NULL;
343 return im ? im->cs.space : EVAS_COLORSPACE_ARGB8888; 176 /* return SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, */
177 /* 2, 2, SDL_WINDOW_OPENGL); */
344} 178}
345 179
346static void * 180static int
347eng_image_alpha_set(void *data EINA_UNUSED, void *image, int has_alpha) 181evgl_eng_native_window_destroy(void *data EINA_UNUSED, void *native_window)
348{ 182{
349 Evas_GL_Image *im; 183 /* SDL_DestroyWindow(native_window); */
350 184 return 1;
351 if (!image) return NULL;
352 im = image;
353 if (im->native.data)
354 {
355 im->alpha = has_alpha;
356 return image;
357 }
358 /* FIXME: can move to gl_common */
359 if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im;
360 if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image;
361 else if ((!has_alpha) && (!im->im->cache_entry.flags.alpha)) return image;
362 if (im->references > 1)
363 {
364 Evas_GL_Image *im_new;
365
366 if (!im->im->image.data)
367 evas_cache_image_load_data(&im->im->cache_entry);
368 evas_gl_common_image_alloc_ensure(im);
369 im_new = evas_gl_common_image_new_from_copied_data(im->gc, im->im->cache_entry.w, im->im->cache_entry.h, im->im->image.data,
370 eng_image_alpha_get(data, image),
371 eng_image_colorspace_get(data, image));
372 if (!im_new) return im;
373 evas_gl_common_image_free(im);
374 im = im_new;
375 }
376 else
377 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
378 im->im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
379 return image;
380} 185}
381 186
382static void * 187static void *
383eng_image_border_set(void *data EINA_UNUSED, void *image, int l EINA_UNUSED, int r EINA_UNUSED, int t EINA_UNUSED, int b EINA_UNUSED) 188evgl_eng_window_surface_create(void *data EINA_UNUSED, void *native_window)
384{ 189{
385 return image; 190 return native_window;
386} 191}
387 192
388static void 193static int
389eng_image_border_get(void *data EINA_UNUSED, void *image EINA_UNUSED, int *l EINA_UNUSED, int *r EINA_UNUSED, int *t EINA_UNUSED, int *b EINA_UNUSED) 194evgl_eng_window_surface_destroy(void *data EINA_UNUSED,
195 void *surface EINA_UNUSED)
390{ 196{
197 return 1;
391} 198}
392 199
393static char * 200static void *
394eng_image_comment_get(void *data EINA_UNUSED, void *image, char *key EINA_UNUSED) 201evgl_eng_context_create(void *data, void *share_ctx EINA_UNUSED)
395{ 202{
396 Evas_GL_Image *im = image; 203 Render_Engine *re = data;
397
398 if (im && im->im) return im->im->info.comment;
399 return NULL;
400}
401 204
402static char * 205 SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
403eng_image_format_get(void *data EINA_UNUSED, void *image EINA_UNUSED) 206 return SDL_GL_CreateContext(re->generic.software.ob->window);
404{
405 return NULL;
406} 207}
407 208
408static void 209static int
409eng_image_colorspace_set(void *data EINA_UNUSED, void *image, Evas_Colorspace cspace) 210evgl_eng_context_destroy(void *data EINA_UNUSED, void *context)
410{ 211{
411 Evas_GL_Image *im; 212 SDL_GL_DeleteContext(context);
412 213 return 1;
413 if (!image) return;
414 im = image;
415 if (im->native.data) return;
416 /* FIXME: can move to gl_common */
417 if (im->cs.space == cspace) return;
418 evas_gl_common_image_alloc_ensure(im);
419 evas_cache_image_colorspace(&im->im->cache_entry, cspace);
420 switch (cspace)
421 {
422 case EVAS_COLORSPACE_ARGB8888:
423 if (im->cs.data)
424 {
425 if (!im->cs.no_free) free(im->cs.data);
426 im->cs.data = NULL;
427 im->cs.no_free = 0;
428 }
429 break;
430 case EVAS_COLORSPACE_YCBCR422P601_PL:
431 case EVAS_COLORSPACE_YCBCR422P709_PL:
432 case EVAS_COLORSPACE_YCBCR422601_PL:
433 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
434 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
435 if (im->tex) evas_gl_common_texture_free(im->tex, EINA_TRUE);
436 im->tex = NULL;
437 if (im->cs.data)
438 {
439 if (!im->cs.no_free) free(im->cs.data);
440 }
441 im->cs.data = calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
442 im->cs.no_free = 0;
443 break;
444 default:
445 abort();
446 break;
447 }
448 im->cs.space = cspace;
449} 214}
450 215
451///////////////////////////////////////////////////////////////////////// 216static const char *
452// 217evgl_eng_string_get(void *data EINA_UNUSED)
453//
454typedef struct _Native Native;
455
456struct _Native
457{
458 Evas_Native_Surface ns;
459
460#ifdef GL_GLES
461 EGLSurface egl_surface;
462#endif
463};
464
465static void *
466eng_image_native_set(void *data EINA_UNUSED, void *image EINA_UNUSED, void *native EINA_UNUSED)
467{ 218{
468 return NULL; 219 const char *(*glGetString)(GLenum n);
469}
470 220
471static void * 221 glGetString = SDL_GL_GetProcAddress("glGetString");
472eng_image_native_get(void *data EINA_UNUSED, void *image EINA_UNUSED) 222 if (glGetString) return glGetString(GL_EXTENSIONS);
473{
474 return NULL; 223 return NULL;
475} 224}
476 225
477//
478//
479/////////////////////////////////////////////////////////////////////////
480
481static void * 226static void *
482eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo) 227evgl_eng_proc_address_get(const char *name)
483{ 228{
484 Render_Engine *re = data; 229 return SDL_GL_GetProcAddress(name);
485
486 *error = EVAS_LOAD_ERROR_NONE;
487 return evas_gl_common_image_load(re->gl_context, file, key, lo, error);
488} 230}
489 231
490static void * 232static int
491eng_image_mmap(void *data, Eina_File *f, const char *key, int *error, Evas_Image_Load_Opts *lo) 233evgl_eng_rotation_angle_get(void *data EINA_UNUSED)
492{ 234{
493 Render_Engine *re = data; 235 return 0;
494
495 *error = EVAS_LOAD_ERROR_NONE;
496 return evas_gl_common_image_mmap(re->gl_context, f, key, lo, error);
497} 236}
498 237
499static void * 238static const EVGL_Interface evgl_funcs =
500eng_image_new_from_data(void *data, int w, int h, DATA32 *image_data, int alpha, Evas_Colorspace cspace)
501{ 239{
502 Render_Engine *re = data; 240 evgl_eng_display_get,
241 evgl_eng_evas_surface_get,
242 evgl_eng_native_window_create,
243 evgl_eng_native_window_destroy,
244 evgl_eng_window_surface_create,
245 evgl_eng_window_surface_destroy,
246 evgl_eng_context_create,
247 evgl_eng_context_destroy,
248 evgl_eng_make_current,
249 evgl_eng_proc_address_get,
250 evgl_eng_string_get,
251 evgl_eng_rotation_angle_get
252};
503 253
504 return evas_gl_common_image_new_from_data(re->gl_context, w, h, image_data, alpha, cspace);
505}
506 254
507static void * 255static void *
508eng_image_new_from_copied_data(void *data, int w, int h, DATA32 *image_data, int alpha, Evas_Colorspace cspace) 256eng_info(Evas *e EINA_UNUSED)
509{ 257{
510 Render_Engine *re = data; 258 Evas_Engine_Info_GL_SDL *info;
511
512 return evas_gl_common_image_new_from_copied_data(re->gl_context, w, h, image_data, alpha, cspace);
513}
514 259
515static void 260 info = calloc(1, sizeof(Evas_Engine_Info_GL_SDL));
516eng_image_free(void *data EINA_UNUSED, void *image) 261 if (!info) return NULL;
517{ 262 info->magic.magic = rand();
518 if (image) evas_gl_common_image_free(image); 263 return info;
519} 264}
520 265
521static void 266static void
522eng_image_size_get(void *data EINA_UNUSED, void *image, int *w, int *h) 267eng_info_free(Evas *e EINA_UNUSED, void *info)
523{ 268{
524 if (!image) 269 Evas_Engine_Info_GL_SDL *in;
525 { 270 in = (Evas_Engine_Info_GL_SDL *)info;
526 *w = 0; 271 free(in);
527 *h = 0;
528 return;
529 }
530 if (w) *w = ((Evas_GL_Image *)image)->w;
531 if (h) *h = ((Evas_GL_Image *)image)->h;
532} 272}
533 273
534static void * 274static int
535eng_image_size_set(void *data, void *image, int w, int h) 275eng_setup(Evas *eo_e, void *in)
536{ 276{
537 Render_Engine *re; 277 Evas_Public_Data *e = eo_data_scope_get(eo_e, EVAS_CANVAS_CLASS);
538 Evas_GL_Image *im = image; 278 Render_Engine *re = NULL;
539 Evas_GL_Image *im_old; 279 Outbuf *ob = NULL;
540 280 Evas_Engine_Info_GL_SDL *info;
541 re = (Render_Engine *)data;
542 if (!im) return NULL;
543 if (im->native.data)
544 {
545 im->w = w;
546 im->h = h;
547 return image;
548 }
549 if ((im->tex) && (im->tex->pt->dyn.img))
550 {
551 evas_gl_common_texture_free(im->tex, EINA_TRUE);
552 im->tex = NULL;
553 im->w = w;
554 im->h = h;
555 im->tex = evas_gl_common_texture_dynamic_new(im->gc, im);
556 return image;
557 }
558 im_old = image;
559
560 switch (eng_image_colorspace_get(data, image))
561 {
562 case EVAS_COLORSPACE_YCBCR422P601_PL:
563 case EVAS_COLORSPACE_YCBCR422P709_PL:
564 case EVAS_COLORSPACE_YCBCR422601_PL:
565 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
566 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
567 w &= ~0x1;
568 break;
569 }
570
571 evas_gl_common_image_alloc_ensure(im_old);
572 if ((im_old->im) &&
573 ((int)im_old->im->cache_entry.w == w) &&
574 ((int)im_old->im->cache_entry.h == h))
575 return image;
576 if (im_old)
577 {
578 im = evas_gl_common_image_new(re->gl_context, w, h,
579 eng_image_alpha_get(data, image),
580 eng_image_colorspace_get(data, image));
581 evas_gl_common_image_free(im_old);
582 }
583 else
584 im = evas_gl_common_image_new(re->gl_context, w, h, 1, EVAS_COLORSPACE_ARGB8888);
585 return im;
586}
587 281
588static void * 282 info = (Evas_Engine_Info_GL_SDL *)in;
589eng_image_dirty_region(void *data EINA_UNUSED, void *image, int x, int y, int w, int h)
590{
591 Evas_GL_Image *im = image;
592 283
593 if (!image) return NULL; 284 ob = _sdl_output_setup(e->output.w, e->output.h,
594 if (im->native.data) return image; 285 info->flags.fullscreen,
595 evas_gl_common_image_dirty(image, x, y, w, h); 286 info->flags.noframe,
596 return image; 287 info);
597} 288 if (!ob) goto on_error;
289
290 re = calloc(1, sizeof (Render_Engine));
291 if (!re) goto on_error;
292
293
294 if (!evas_render_engine_gl_generic_init(&re->generic, ob, NULL,
295 _outbuf_get_rot,
296 _outbuf_reconfigure,
297 _outbuf_region_first_rect,
298 _outbuf_new_region_for_update,
299 _outbuf_push_updated_region,
300 _outbuf_free_region_for_update,
301 NULL,
302 _outbuf_flush,
303 _outbuf_free,
304 _window_use,
305 _window_gl_context_get,
306 _window_egl_display_get,
307 _window_gl_context_new,
308 _window_gl_context_use,
309 &evgl_funcs,
310 e->output.w, e->output.h))
311 goto on_error;
598 312
599static void * 313 e->engine.data.output = re;
600eng_image_data_get(void *data EINA_UNUSED, void *image, int to_write, DATA32 **image_data, int *err) 314 if (!e->engine.data.output)
601{ 315 return 0;
602 Evas_GL_Image *im; 316 e->engine.func = &func;
603 int error; 317 e->engine.data.context = e->engine.func->context_new(e->engine.data.output);
604
605 if (!image)
606 {
607 *image_data = NULL;
608 if (err) *err = EVAS_LOAD_ERROR_GENERIC;
609 return NULL;
610 }
611 im = image;
612 if (im->native.data)
613 {
614 *image_data = NULL;
615 if (err) *err = EVAS_LOAD_ERROR_NONE;
616 return im;
617 }
618 error = evas_cache_image_load_data(&im->im->cache_entry);
619 evas_gl_common_image_alloc_ensure(im);
620 switch (im->cs.space)
621 {
622 case EVAS_COLORSPACE_ARGB8888:
623 if (to_write)
624 {
625 if (im->references > 1)
626 {
627 Evas_GL_Image *im_new;
628
629 im_new = evas_gl_common_image_new_from_copied_data(im->gc, im->im->cache_entry.w, im->im->cache_entry.h, im->im->image.data,
630 eng_image_alpha_get(data, image),
631 eng_image_colorspace_get(data, image));
632 if (!im_new)
633 {
634 *image_data = NULL;
635 if (err) *err = error;
636 return im;
637 }
638 evas_gl_common_image_free(im);
639 im = im_new;
640 }
641 else
642 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
643 }
644 *image_data = im->im->image.data;
645 break;
646 case EVAS_COLORSPACE_YCBCR422P601_PL:
647 case EVAS_COLORSPACE_YCBCR422P709_PL:
648 case EVAS_COLORSPACE_YCBCR422601_PL:
649 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
650 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
651 *image_data = im->cs.data;
652 break;
653 default:
654 abort();
655 break;
656 }
657 if (err) *err = error;
658 return im;
659}
660 318
661static void * 319 /* if we haven't initialized - init (automatic abort if already done) */
662eng_image_data_put(void *data EINA_UNUSED, void *image, DATA32 *image_data) 320 evas_common_cpu_init();
663{ 321 evas_common_blend_init();
664 Evas_GL_Image *im, *im2; 322 evas_common_image_init();
323 evas_common_convert_init();
324 evas_common_scale_init();
325 evas_common_rectangle_init();
326 evas_common_polygon_init();
327 evas_common_line_init();
328 evas_common_font_init();
329 evas_common_draw_init();
330 evas_common_tilebuf_init();
665 331
666 if (!image) return NULL; 332 return 1;
667 im = image;
668 if (im->native.data) return image;
669 evas_gl_common_image_alloc_ensure(im);
670 switch (im->cs.space)
671 {
672 case EVAS_COLORSPACE_ARGB8888:
673 if (image_data != im->im->image.data)
674 {
675 int w, h;
676
677 w = im->im->cache_entry.w;
678 h = im->im->cache_entry.h;
679 im2 = eng_image_new_from_data(data, w, h, image_data,
680 eng_image_alpha_get(data, image),
681 eng_image_colorspace_get(data, image));
682 if (!im2) return im;
683 evas_gl_common_image_free(im);
684 im = im2;
685 }
686 break;
687 case EVAS_COLORSPACE_YCBCR422P601_PL:
688 case EVAS_COLORSPACE_YCBCR422P709_PL:
689 case EVAS_COLORSPACE_YCBCR422601_PL:
690 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
691 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
692 if (image_data != im->cs.data)
693 {
694 if (im->cs.data)
695 {
696 if (!im->cs.no_free) free(im->cs.data);
697 }
698 im->cs.data = image_data;
699 }
700 break;
701 default:
702 abort();
703 break;
704 }
705 /* hmmm - but if we wrote... why bother? */
706 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
707 return im;
708}
709 333
710static void 334 on_error:
711eng_image_data_preload_request(void *data EINA_UNUSED, void *image, const Eo *target) 335 if (ob) _outbuf_free(ob);
712{ 336 free(ob);
713 Evas_GL_Image *gim = image; 337 free(re);
714 RGBA_Image *im; 338 return 0;
715
716 if (!gim) return;
717 if (gim->native.data) return;
718 im = (RGBA_Image *)gim->im;
719 if (!im) return;
720 evas_cache_image_preload_data(&im->cache_entry, target, NULL, NULL, NULL);
721} 339}
722 340
723static void 341static void
724eng_image_data_preload_cancel(void *data EINA_UNUSED, void *image, const Eo *target) 342eng_output_free(void *data)
725{
726 Evas_GL_Image *gim = image;
727 RGBA_Image *im;
728
729 if (!gim) return;
730 if (gim->native.data) return;
731 im = (RGBA_Image *)gim->im;
732 if (!im) return;
733 evas_cache_image_preload_cancel(&im->cache_entry, target);
734}
735
736static Eina_Bool
737eng_image_draw(void *data, void *context, void *surface, void *image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, int smooth, Eina_Bool do_async EINA_UNUSED)
738{ 343{
739 Render_Engine *re; 344 Render_Engine *re = data;
740 345
741 re = (Render_Engine *)data; 346 evas_render_engine_software_generic_clean(&re->generic.software);
742 if (!image) return EINA_FALSE;
743 evas_gl_common_context_target_surface_set(re->gl_context, surface);
744 re->gl_context->dc = context;
745 evas_gl_common_image_draw(re->gl_context, image,
746 src_x, src_y, src_w, src_h,
747 dst_x, dst_y, dst_w, dst_h,
748 smooth);
749 return EINA_FALSE;
750} 347}
751 348
752static void 349static void
753eng_image_scale_hint_set(void *data EINA_UNUSED, void *image, int hint) 350eng_output_dump(void *data)
754{
755 if (image) evas_gl_common_image_scale_hint_set(image, hint);
756}
757
758static Eina_Bool
759eng_image_map_draw(void *data EINA_UNUSED, void *context, void *surface, void *image, RGBA_Map *m, int smooth, int level, Eina_Bool do_async)
760{ 351{
761 Evas_GL_Image *gim = image;
762 Render_Engine *re; 352 Render_Engine *re;
763 353
764 re = (Render_Engine *)data; 354 re = (Render_Engine *)data;
765 evas_gl_common_context_target_surface_set(re->gl_context, surface); 355 evas_common_image_image_all_unload();
766 re->gl_context->dc = context; 356 evas_common_font_font_all_unload();
767 if (m->count != 4) 357 glsym_evas_gl_common_image_all_unload(re->generic.software.ob->gl_context);
768 {
769 // FIXME: nash - you didn't fix this
770 abort();
771 }
772 if ((m->pts[0].x == m->pts[3].x) &&
773 (m->pts[1].x == m->pts[2].x) &&
774 (m->pts[0].y == m->pts[1].y) &&
775 (m->pts[3].y == m->pts[2].y) &&
776 (m->pts[0].x <= m->pts[1].x) &&
777 (m->pts[0].y <= m->pts[2].y) &&
778 (m->pts[0].u == 0) &&
779 (m->pts[0].v == 0) &&
780 (m->pts[1].u == (gim->w << FP)) &&
781 (m->pts[1].v == 0) &&
782 (m->pts[2].u == (gim->w << FP)) &&
783 (m->pts[2].v == (gim->h << FP)) &&
784 (m->pts[3].u == 0) &&
785 (m->pts[3].v == (gim->h << FP)) &&
786 (m->pts[0].col == 0xffffffff) &&
787 (m->pts[1].col == 0xffffffff) &&
788 (m->pts[2].col == 0xffffffff) &&
789 (m->pts[3].col == 0xffffffff))
790 {
791 int dx, dy, dw, dh;
792
793 dx = m->pts[0].x >> FP;
794 dy = m->pts[0].y >> FP;
795 dw = (m->pts[2].x >> FP) - dx;
796 dh = (m->pts[2].y >> FP) - dy;
797 eng_image_draw(data, context, surface, image,
798 0, 0, gim->w, gim->h, dx, dy, dw, dh, smooth, do_async);
799 }
800 else
801 {
802 evas_gl_common_image_map_draw(re->gl_context, image, m->count, &m->pts[0],
803 smooth, level);
804 }
805
806 return EINA_FALSE;
807} 358}
808 359
809static void * 360static Eina_Bool
810eng_image_map_surface_new(void *data EINA_UNUSED, int w, int h, int alpha) 361eng_canvas_alpha_get(void *data EINA_UNUSED, void *info EINA_UNUSED)
811{ 362{
812 Render_Engine *re; 363 return 0;
813
814 re = (Render_Engine *)data;
815 return evas_gl_common_image_surface_new(re->gl_context, w, h, alpha);
816} 364}
817 365
818static void 366static void
819eng_image_map_surface_free(void *data EINA_UNUSED, void *surface) 367gl_symbols(void)
820{ 368{
821 evas_gl_common_image_free(surface); 369#define LINK2GENERIC(sym) \
822} 370 glsym_##sym = dlsym(RTLD_DEFAULT, #sym);
823 371
824static int 372 LINK2GENERIC(evas_gl_symbols);
825eng_image_scale_hint_get(void *data EINA_UNUSED, void *image) 373 LINK2GENERIC(evas_gl_common_context_new);
826{ 374 LINK2GENERIC(evas_gl_common_context_free);
827 Evas_GL_Image *gim = image; 375 LINK2GENERIC(evas_gl_common_context_use);
828 if (!gim) return EVAS_IMAGE_SCALE_HINT_NONE; 376 LINK2GENERIC(evas_gl_common_context_flush);
829 return gim->scale_hint; 377 LINK2GENERIC(evas_gl_common_image_all_unload);
830} 378 LINK2GENERIC(evas_gl_common_context_resize);
379 LINK2GENERIC(evas_gl_preload_render_lock);
831 380
832static Eina_Bool 381 glsym_evas_gl_symbols((void*)SDL_GL_GetProcAddress);
833eng_font_draw(void *data, void *context, void *surface, Evas_Font_Set *font EINA_UNUSED, int x, int y, int w EINA_UNUSED, int h EINA_UNUSED, int ow EINA_UNUSED, int oh EINA_UNUSED, Evas_Text_Props *intl_props, Eina_Bool do_async EINA_UNUSED)
834{
835 Render_Engine *re = data;
836
837 evas_gl_common_context_target_surface_set(re->gl_context, surface);
838 re->gl_context->dc = context;
839 {
840 // FIXME: put im into context so we can free it
841 static RGBA_Image *im = NULL;
842
843 if (!im)
844 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
845 im->cache_entry.w = re->w;
846 im->cache_entry.h = re->h;
847 evas_common_draw_context_font_ext_set(context,
848 re->gl_context,
849 evas_gl_font_texture_new,
850 evas_gl_font_texture_free,
851 evas_gl_font_texture_draw);
852 evas_common_font_draw_prepare(intl_props);
853 evas_common_font_draw(im, context, x, y, intl_props->glyphs);
854 evas_common_draw_context_font_ext_set(context,
855 NULL,
856 NULL,
857 NULL,
858 NULL);
859 }
860
861 return EINA_FALSE;
862}
863
864static Eina_Bool
865eng_canvas_alpha_get(void *data EINA_UNUSED, void *info EINA_UNUSED)
866{
867 // FIXME: support ARGB gl targets!!!
868 return EINA_FALSE;
869}
870
871static int
872eng_image_load_error_get(void *data EINA_UNUSED, void *image)
873{
874 Evas_GL_Image *im;
875
876 if (!image) return EVAS_LOAD_ERROR_NONE;
877 im = image;
878 return im->im->cache_entry.load_error;
879} 382}
880 383
881
882static int 384static int
883module_open(Evas_Module *em) 385module_open(Evas_Module *em)
884{ 386{
885 if (!em) return 0; 387 if (!em) return 0;
886 if (!evas_gl_common_module_open()) return 0;
887 /* get whatever engine module we inherit from */ 388 /* get whatever engine module we inherit from */
888 if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0; 389 if (!_evas_module_engine_inherit(&pfunc, "gl_generic")) return 0;
889 if (_evas_engine_GL_SDL_log_dom < 0) 390 if (_evas_engine_GL_SDL_log_dom < 0)
890 _evas_engine_GL_SDL_log_dom = eina_log_domain_register 391 _evas_engine_GL_SDL_log_dom = eina_log_domain_register
891 ("evas-gl_sdl", EVAS_DEFAULT_LOG_COLOR); 392 ("evas-gl_sdl", EVAS_DEFAULT_LOG_COLOR);
@@ -903,75 +404,10 @@ module_open(Evas_Module *em)
903 ORD(setup); 404 ORD(setup);
904 ORD(canvas_alpha_get); 405 ORD(canvas_alpha_get);
905 ORD(output_free); 406 ORD(output_free);
906 ORD(output_resize);
907 ORD(output_tile_size_set);
908 ORD(output_redraws_rect_add);
909 ORD(output_redraws_rect_del);
910 ORD(output_redraws_clear);
911 ORD(output_redraws_next_update_get);
912 ORD(output_redraws_next_update_push);
913 ORD(context_cutout_add);
914 ORD(context_cutout_clear);
915 ORD(output_flush);
916 ORD(output_idle_flush);
917 ORD(output_dump); 407 ORD(output_dump);
918 ORD(rectangle_draw); 408
919 ORD(line_draw); 409 gl_symbols();
920 ORD(polygon_point_add); 410
921 ORD(polygon_points_clear);
922 ORD(polygon_draw);
923
924 ORD(image_load);
925 ORD(image_mmap);
926 ORD(image_new_from_data);
927 ORD(image_new_from_copied_data);
928 ORD(image_free);
929 ORD(image_size_get);
930 ORD(image_size_set);
931 ORD(image_dirty_region);
932 ORD(image_data_get);
933 ORD(image_data_put);
934 ORD(image_data_preload_request);
935 ORD(image_data_preload_cancel);
936 ORD(image_alpha_set);
937 ORD(image_alpha_get);
938 ORD(image_border_set);
939 ORD(image_border_get);
940 ORD(image_draw);
941 ORD(image_comment_get);
942 ORD(image_format_get);
943 ORD(image_colorspace_set);
944 ORD(image_colorspace_get);
945 ORD(image_native_set);
946 ORD(image_native_get);
947 ORD(font_draw);
948
949 ORD(image_scale_hint_set);
950 ORD(image_scale_hint_get);
951
952 ORD(image_map_draw);
953 ORD(image_map_surface_new);
954 ORD(image_map_surface_free);
955
956// ORD(image_content_hint_set);
957// ORD(image_content_hint_get);
958
959// ORD(image_cache_flush);
960// ORD(image_cache_set);
961// ORD(image_cache_get);
962
963// ORD(gl_surface_create);
964// ORD(gl_surface_destroy);
965// ORD(gl_context_create);
966// ORD(gl_context_destroy);
967// ORD(gl_make_current);
968// ORD(gl_proc_address_get);
969// ORD(gl_native_surface_get);
970
971// ORD(gl_api_get);
972
973 ORD(image_load_error_get);
974
975 /* now advertise out own api */ 411 /* now advertise out own api */
976 em->functions = (void *)(&func); 412 em->functions = (void *)(&func);
977 return 1; 413 return 1;
@@ -981,7 +417,6 @@ static void
981module_close(Evas_Module *em EINA_UNUSED) 417module_close(Evas_Module *em EINA_UNUSED)
982{ 418{
983 eina_log_domain_unregister(_evas_engine_GL_SDL_log_dom); 419 eina_log_domain_unregister(_evas_engine_GL_SDL_log_dom);
984 evas_gl_common_module_close();
985} 420}
986 421
987static Evas_Module_Api evas_modapi = 422static Evas_Module_Api evas_modapi =
@@ -1001,28 +436,16 @@ EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, gl_sdl);
1001EVAS_EINA_MODULE_DEFINE(engine, gl_sdl); 436EVAS_EINA_MODULE_DEFINE(engine, gl_sdl);
1002#endif 437#endif
1003 438
1004static void* 439static Outbuf *
1005_sdl_output_setup (int w, int h, int fullscreen, int noframe) 440_sdl_output_setup(int w, int h, int fullscreen EINA_UNUSED, int noframe EINA_UNUSED, Evas_Engine_Info_GL_SDL *info)
1006{ 441{
1007 Render_Engine *re = calloc(1, sizeof(Render_Engine)); 442 Outbuf *ob = NULL;
1008 SDL_Surface *surface; 443 const char *(*glGetString)(GLenum n);
1009
1010 /* if we haven't initialized - init (automatic abort if already done) */
1011 evas_common_cpu_init();
1012 evas_common_blend_init();
1013 evas_common_image_init();
1014 evas_common_convert_init();
1015 evas_common_scale_init();
1016 evas_common_rectangle_init();
1017 evas_common_polygon_init();
1018 evas_common_line_init();
1019 evas_common_font_init();
1020 evas_common_draw_init();
1021 evas_common_tilebuf_init();
1022 444
445 if (!info->window) return NULL;
1023 if (w <= 0) w = 640; 446 if (w <= 0) w = 640;
1024 if (h <= 0) h = 480; 447 if (h <= 0) h = 480;
1025 448
1026 /* GL Initialization */ 449 /* GL Initialization */
1027#ifdef HAVE_SDL_GL_CONTEXT_VERSION 450#ifdef HAVE_SDL_GL_CONTEXT_VERSION
1028 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); 451 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
@@ -1033,33 +456,37 @@ _sdl_output_setup (int w, int h, int fullscreen, int noframe)
1033 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); 456 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
1034 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); 457 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
1035 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 458 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
1036 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);
1037 459
1038 surface = SDL_SetVideoMode(w, h, 32, EVAS_SDL_GL_FLAG 460 ob = calloc(1, sizeof(Outbuf));
1039 | (fullscreen ? SDL_FULLSCREEN : 0) 461 if (!ob) return NULL;
1040 | (noframe ? SDL_NOFRAME : 0));
1041 462
1042 if (!surface) 463 ob->window = info->window;
464 ob->w = w;
465 ob->h = h;
466 ob->info = info;
467 ob->context = SDL_GL_CreateContext(ob->window);
468 if (!ob->context)
1043 { 469 {
1044 CRI("SDL_SetVideoMode [ %i x %i x 32 ] failed. %s", w, h, SDL_GetError()); 470 ERR("Impossible to create a context for : %p", info->window);
1045 SDL_Quit(); 471 goto on_error;
1046 exit(-1);
1047 } 472 }
1048 473
1049 INF("Screen Depth: %d, Vendor: '%s', Renderer: '%s', Version: '%s'", SDL_GetVideoSurface()->format->BitsPerPixel, glGetString(GL_VENDOR), glGetString(GL_RENDERER), glGetString(GL_VERSION)); 474 glGetString = SDL_GL_GetProcAddress("glGetString");
1050 475
1051 re->gl_context = evas_gl_common_context_new(); 476 INF("Vendor: '%s', Renderer: '%s', Version: '%s'",
1052 if (!re->gl_context) 477 glGetString(GL_VENDOR), glGetString(GL_RENDERER), glGetString(GL_VERSION));
1053 { 478
1054 free(re); 479 ob->gl_context = glsym_evas_gl_common_context_new();
1055 return NULL; 480 if (!ob->gl_context) goto on_error;
1056 } 481
1057 evas_gl_common_context_use(re->gl_context); 482 glsym_evas_gl_common_context_use(ob->gl_context);
1058 evas_gl_common_context_resize(re->gl_context, w, h, re->gl_context->rot); 483 glsym_evas_gl_common_context_resize(ob->gl_context, w, h, ob->gl_context->rot);
1059 484
1060 /* End GL Initialization */ 485 /* End GL Initialization */
1061 re->w = w; 486 return ob;
1062 re->h = h;
1063 return re;
1064}
1065 487
488 on_error:
489 if (ob && ob->window) SDL_DestroyWindow(ob->window);
490 free(ob);
491 return NULL;
492}
diff --git a/src/modules/evas/engines/gl_sdl/evas_engine.h b/src/modules/evas/engines/gl_sdl/evas_engine.h
index 459dd7d87a..92c97fd7ba 100644
--- a/src/modules/evas/engines/gl_sdl/evas_engine.h
+++ b/src/modules/evas/engines/gl_sdl/evas_engine.h
@@ -4,17 +4,16 @@
4#define _EVAS_ENGINE_SDL_H 4#define _EVAS_ENGINE_SDL_H
5 5
6#include "config.h" 6#include "config.h"
7#include <SDL/SDL.h> 7#include <SDL2/SDL.h>
8#ifdef GL_GLES 8#ifdef GL_GLES
9# include <EGL/egl.h> 9# include <SDL2/SDL_opengles.h>
10# include <SDL/SDL_opengles.h>
11# ifdef HAVE_SDL_FLAG_OPENGLES 10# ifdef HAVE_SDL_FLAG_OPENGLES
12# define EVAS_SDL_GL_FLAG SDL_OPENGLES 11# define EVAS_SDL_GL_FLAG SDL_OPENGLES
13# else 12# else
14# define EVAS_SDL_GL_FLAG SDL_OPENGL /* This probably won't work? */ 13# define EVAS_SDL_GL_FLAG SDL_OPENGL /* This probably won't work? */
15# endif 14# endif
16#else 15#else
17# include <SDL/SDL_opengl.h> 16# include <SDL2/SDL_opengl.h>
18# define EVAS_SDL_GL_FLAG SDL_OPENGL 17# define EVAS_SDL_GL_FLAG SDL_OPENGL
19#endif 18#endif
20#include "evas_common_private.h" 19#include "evas_common_private.h"
@@ -23,6 +22,8 @@
23#include "Evas.h" 22#include "Evas.h"
24#include "Evas_Engine_GL_SDL.h" 23#include "Evas_Engine_GL_SDL.h"
25 24
25#include "../gl_generic/Evas_Engine_GL_Generic.h"
26
26extern int _evas_engine_GL_SDL_log_dom ; 27extern int _evas_engine_GL_SDL_log_dom ;
27#ifdef ERR 28#ifdef ERR
28# undef ERR 29# undef ERR
@@ -50,10 +51,12 @@ extern int _evas_engine_GL_SDL_log_dom ;
50#define CRI(...) EINA_LOG_DOM_CRIT(_evas_engine_GL_SDL_log_dom, __VA_ARGS__) 51#define CRI(...) EINA_LOG_DOM_CRIT(_evas_engine_GL_SDL_log_dom, __VA_ARGS__)
51 52
52typedef struct _Render_Engine Render_Engine; 53typedef struct _Render_Engine Render_Engine;
53struct _Render_Engine 54
55struct _Outbuf
54{ 56{
55 Evas_Engine_Info_GL_SDL *info; 57 Evas_Engine_Info_GL_SDL *info;
56 int w, h; 58 SDL_Window *window;
59 SDL_GLContext *context;
57 60
58 Evas_Engine_GL_Context *gl_context; 61 Evas_Engine_GL_Context *gl_context;
59 struct { 62 struct {
@@ -68,6 +71,12 @@ struct _Render_Engine
68 EGLDisplay egl_disp; 71 EGLDisplay egl_disp;
69#endif 72#endif
70 73
74 int w, h;
75};
76
77struct _Render_Engine
78{
79 Render_Engine_GL_Generic generic;
71}; 80};
72 81
73#endif 82#endif