summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Guyomarc'h <jean.guyomarch@openwide.fr>2016-08-24 17:58:29 +0200
committerJean Guyomarc'h <jean@guyomarch.bzh>2016-08-25 23:29:27 +0200
commit60215a5c53b8d32d0c7e7da0634b16cb24579178 (patch)
tree21700f6403ca77f2a1528dc6c6fed679489c0b23
parentd8e488b1c80fad6a0057988015f955634877a9ca (diff)
evas-gl_cocoa: migrate to gl_generic infrastructure
It has been a long journey, but here we are at last... The infamous gl_cocoa engine has been migrated to the gl_generic infrastructure. This should provide great improvements and hopefully reduce side-channels b0rkage. Fonts seems better, scrolling is smoother, expedite does not segfault anymore... I haven't found a regression with elementary_test, elementary_config, terminology, expedite.
-rw-r--r--m4/evas_check_engine.m41
-rw-r--r--src/Makefile_Evas.am21
-rw-r--r--src/modules/evas/engines/gl_cocoa/evas_engine.c1403
-rw-r--r--src/modules/evas/engines/gl_cocoa/evas_engine.h62
-rw-r--r--src/modules/evas/engines/gl_cocoa/evas_outbuf.m245
5 files changed, 400 insertions, 1332 deletions
diff --git a/m4/evas_check_engine.m4 b/m4/evas_check_engine.m4
index b385076cb8..a7e00851ec 100644
--- a/m4/evas_check_engine.m4
+++ b/m4/evas_check_engine.m4
@@ -393,6 +393,7 @@ window = [[NSWindow alloc]
393 [ 393 [
394 have_dep="yes" 394 have_dep="yes"
395 evas_engine_[]$1[]_libs="-framework Cocoa -framework OpenGL" 395 evas_engine_[]$1[]_libs="-framework Cocoa -framework OpenGL"
396 evas_engine_gl_common_libs="$evas_engine_[]$1[]_libdirs"
396 ], 397 ],
397 [have_dep="no"]) 398 [have_dep="no"])
398LIBS="$LIBS_save" 399LIBS="$LIBS_save"
diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am
index 0695e0a19b..e86f8617bc 100644
--- a/src/Makefile_Evas.am
+++ b/src/Makefile_Evas.am
@@ -903,6 +903,9 @@ endif
903if BUILD_ENGINE_EGLFS 903if BUILD_ENGINE_EGLFS
904modules_evas_engines_gl_common_libevas_engine_gl_common_la_CPPFLAGS += @evas_engine_eglfs_cflags@ 904modules_evas_engines_gl_common_libevas_engine_gl_common_la_CPPFLAGS += @evas_engine_eglfs_cflags@
905endif 905endif
906if BUILD_ENGINE_GL_COCOA
907modules_evas_engines_gl_common_libevas_engine_gl_common_la_CPPFLAGS += @evas_engine_gl_cocoa_cflags@
908endif
906modules_evas_engines_gl_common_libevas_engine_gl_common_la_LIBADD = @USE_EVAS_LIBS@ 909modules_evas_engines_gl_common_libevas_engine_gl_common_la_LIBADD = @USE_EVAS_LIBS@
907modules_evas_engines_gl_common_libevas_engine_gl_common_la_DEPENDENCIES = @USE_EVAS_INTERNAL_LIBS@ 910modules_evas_engines_gl_common_libevas_engine_gl_common_la_DEPENDENCIES = @USE_EVAS_INTERNAL_LIBS@
908modules_evas_engines_gl_common_libevas_engine_gl_common_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@ 911modules_evas_engines_gl_common_libevas_engine_gl_common_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@
@@ -915,12 +918,11 @@ dist_installed_evasmainheaders_DATA += modules/evas/engines/gl_cocoa/Evas_Engine
915GL_COCOA_SOURCES = \ 918GL_COCOA_SOURCES = \
916modules/evas/engines/gl_cocoa/evas_engine.c \ 919modules/evas/engines/gl_cocoa/evas_engine.c \
917modules/evas/engines/gl_cocoa/evas_outbuf.m \ 920modules/evas/engines/gl_cocoa/evas_outbuf.m \
918modules/evas/engines/gl_cocoa/evas_engine.h 921modules/evas/engines/gl_cocoa/evas_engine.h \
922modules/evas/engines/gl_cocoa/Evas_Engine_GL_Cocoa.h
919if EVAS_STATIC_BUILD_GL_COCOA 923if EVAS_STATIC_BUILD_GL_COCOA
920lib_evas_libevas_la_SOURCES += $(GL_COCOA_SOURCES) 924lib_evas_libevas_la_SOURCES += $(GL_COCOA_SOURCES)
921lib_evas_libevas_la_CPPFLAGS += \ 925lib_evas_libevas_la_CPPFLAGS += @evas_engine_gl_cocoa_cflags@
922-I$(top_srcdir)/src/modules/evas/engines/gl_common \
923@evas_engine_gl_cocoa_cflags@
924lib_evas_libevas_la_LIBADD += @evas_engine_gl_cocoa_libs@ 926lib_evas_libevas_la_LIBADD += @evas_engine_gl_cocoa_libs@
925else 927else
926engineglcocoapkgdir = $(libdir)/evas/modules/engines/gl_cocoa/$(MODULE_ARCH) 928engineglcocoapkgdir = $(libdir)/evas/modules/engines/gl_cocoa/$(MODULE_ARCH)
@@ -935,20 +937,13 @@ modules_evas_engines_gl_cocoa_module_la_SOURCES = $(GL_COCOA_SOURCES)
935modules_evas_engines_gl_cocoa_module_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ 937modules_evas_engines_gl_cocoa_module_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
936-I$(top_srcdir)/src/lib/evas/include \ 938-I$(top_srcdir)/src/lib/evas/include \
937-I$(top_srcdir)/src/lib/evas/cserve2 \ 939-I$(top_srcdir)/src/lib/evas/cserve2 \
938-I$(top_srcdir)/src/modules/evas/engines/gl_common \
939@EVAS_CFLAGS@ \ 940@EVAS_CFLAGS@ \
940@evas_engine_gl_cocoa_cflags@ 941@evas_engine_gl_cocoa_cflags@
941modules_evas_engines_gl_cocoa_module_la_LIBADD = 942modules_evas_engines_gl_cocoa_module_la_LIBADD = \
942if ! EVAS_STATIC_BUILD_GL_COMMON
943modules_evas_engines_gl_cocoa_module_la_LIBADD += \
944modules/evas/engines/gl_common/libevas_engine_gl_common.la
945endif
946modules_evas_engines_gl_cocoa_module_la_LIBADD += \
947@USE_EVAS_LIBS@ \ 943@USE_EVAS_LIBS@ \
948@evas_engine_gl_cocoa_libs@ 944@evas_engine_gl_cocoa_libs@
949modules_evas_engines_gl_cocoa_module_la_DEPENDENCIES = \ 945modules_evas_engines_gl_cocoa_module_la_DEPENDENCIES = \
950@USE_EVAS_INTERNAL_LIBS@ \ 946@USE_EVAS_INTERNAL_LIBS@
951modules/evas/engines/gl_common/libevas_engine_gl_common.la
952modules_evas_engines_gl_cocoa_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@ 947modules_evas_engines_gl_cocoa_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@
953modules_evas_engines_gl_cocoa_module_la_LIBTOOLFLAGS = --tag=disable-static 948modules_evas_engines_gl_cocoa_module_la_LIBTOOLFLAGS = --tag=disable-static
954endif 949endif
diff --git a/src/modules/evas/engines/gl_cocoa/evas_engine.c b/src/modules/evas/engines/gl_cocoa/evas_engine.c
index d4c2f371d5..20311669d1 100644
--- a/src/modules/evas/engines/gl_cocoa/evas_engine.c
+++ b/src/modules/evas/engines/gl_cocoa/evas_engine.c
@@ -13,24 +13,115 @@ Evas_GL_Common_Context_New glsym_evas_gl_common_context_new = NULL;
13Evas_GL_Common_Context_Call glsym_evas_gl_common_context_free = NULL; 13Evas_GL_Common_Context_Call glsym_evas_gl_common_context_free = NULL;
14Evas_GL_Common_Context_Call glsym_evas_gl_common_context_flush = NULL; 14Evas_GL_Common_Context_Call glsym_evas_gl_common_context_flush = NULL;
15Evas_GL_Common_Context_Call glsym_evas_gl_common_context_use = NULL; 15Evas_GL_Common_Context_Call glsym_evas_gl_common_context_use = NULL;
16Evas_GL_Common_Context_Call glsym_evas_gl_common_context_done = NULL;
16Evas_GL_Common_Context_Resize_Call glsym_evas_gl_common_context_resize = NULL; 17Evas_GL_Common_Context_Resize_Call glsym_evas_gl_common_context_resize = NULL;
18Evas_GL_Common_Context_Call glsym_evas_gl_common_context_newframe = NULL;
19Evas_GL_Preload_Render_Call glsym_evas_gl_preload_render_lock = NULL;
20Evas_GL_Preload_Render_Call glsym_evas_gl_preload_render_unlock = NULL;
21static Evas_GL_Preload glsym_evas_gl_preload_init = NULL;
22static Evas_GL_Preload glsym_evas_gl_preload_shutdown = NULL;
17 23
18int _evas_engine_gl_cocoa_log_dom = -1; 24int _evas_engine_gl_cocoa_log_dom = -1;
19/* function tables - filled in later (func and parent func) */ 25/* function tables - filled in later (func and parent func) */
20static Evas_Func func, pfunc; 26static Evas_Func func, pfunc;
21 27
22/* Function table for GL APIs */
23static Evas_GL_API gl_funcs;
24
25static Eina_Bool _initted = EINA_FALSE; 28static Eina_Bool _initted = EINA_FALSE;
26Eina_Bool _need_context_restore = EINA_FALSE; 29static int _gl_wins = 0;
30
31
32static void *
33evgl_eng_native_window_create(void *data EINA_UNUSED)
34{
35 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(NULL);
36}
37
38static int
39evgl_eng_native_window_destroy(void *data EINA_UNUSED,
40 void *native_window EINA_UNUSED)
41{
42 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(1);
43}
44
45static void *
46evgl_eng_window_surface_create(void *data EINA_UNUSED,
47 void *native_window EINA_UNUSED)
48{
49 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(NULL);
50}
51
52static int
53evgl_eng_window_surface_destroy(void *data EINA_UNUSED,
54 void *surface EINA_UNUSED)
55{
56 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(1);
57}
58
59static void *
60evgl_eng_context_create(void *data EINA_UNUSED,
61 void *share_ctx EINA_UNUSED,
62 Evas_GL_Context_Version version EINA_UNUSED)
63{
64 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(NULL);
65}
66
67static int
68evgl_eng_context_destroy(void *data EINA_UNUSED,
69 void *context EINA_UNUSED)
70{
71 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(1);
72}
27 73
28void 74static int
29_context_restore(void) 75evgl_eng_make_current(void *data EINA_UNUSED,
76 void *surface EINA_UNUSED,
77 void *context EINA_UNUSED,
78 int flush EINA_UNUSED)
30{ 79{
80 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(EINA_FALSE);
31} 81}
32 82
33static void * 83static void *
84evgl_eng_proc_address_get(const char *name EINA_UNUSED)
85{
86 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(NULL);
87}
88
89static const char *
90evgl_eng_string_get(void *data EINA_UNUSED)
91{
92 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(NULL);
93}
94
95static int
96evgl_eng_rotation_angle_get(void *data EINA_UNUSED)
97{
98 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(0);
99}
100
101static const EVGL_Interface evgl_funcs =
102{
103 NULL,
104 NULL,
105 evgl_eng_native_window_create,
106 evgl_eng_native_window_destroy,
107 evgl_eng_window_surface_create,
108 evgl_eng_window_surface_destroy,
109 evgl_eng_context_create,
110 evgl_eng_context_destroy,
111 evgl_eng_make_current,
112 evgl_eng_proc_address_get,
113 evgl_eng_string_get,
114 evgl_eng_rotation_angle_get,
115 NULL, // PBuffer
116 NULL, // PBuffer
117 NULL, // OpenGL-ES 1
118 NULL, // OpenGL-ES 1
119 NULL, // OpenGL-ES 1
120 NULL, // native_win_surface_config_get
121};
122
123
124static void *
34eng_info(Evas *e EINA_UNUSED) 125eng_info(Evas *e EINA_UNUSED)
35{ 126{
36 Evas_Engine_Info_GL_Cocoa *info; 127 Evas_Engine_Info_GL_Cocoa *info;
@@ -38,7 +129,7 @@ eng_info(Evas *e EINA_UNUSED)
38 info = calloc(1, sizeof(*info)); 129 info = calloc(1, sizeof(*info));
39 if (EINA_UNLIKELY(!info)) 130 if (EINA_UNLIKELY(!info))
40 { 131 {
41 CRI("Faield to allocate memory"); 132 CRI("Failed to allocate memory");
42 return NULL; 133 return NULL;
43 } 134 }
44 info->magic.magic = rand(); 135 info->magic.magic = rand();
@@ -61,8 +152,8 @@ eng_setup(Evas *evas, void *in)
61 Evas_Public_Data *e; 152 Evas_Public_Data *e;
62 Render_Engine *re = NULL; 153 Render_Engine *re = NULL;
63 Outbuf *ob; 154 Outbuf *ob;
155 Eina_Bool chk;
64 156
65 DBG("Engine Setup");
66 e = efl_data_scope_get(evas, EVAS_CANVAS_CLASS); 157 e = efl_data_scope_get(evas, EVAS_CANVAS_CLASS);
67 if (EINA_UNLIKELY(!e)) 158 if (EINA_UNLIKELY(!e))
68 { 159 {
@@ -77,7 +168,7 @@ eng_setup(Evas *evas, void *in)
77 if (!_initted) 168 if (!_initted)
78 { 169 {
79 evas_common_init(); 170 evas_common_init();
80 // TODO gl_preload_init() 171 glsym_evas_gl_preload_init();
81 _initted = EINA_TRUE; 172 _initted = EINA_TRUE;
82 } 173 }
83 174
@@ -88,29 +179,56 @@ eng_setup(Evas *evas, void *in)
88 goto err; 179 goto err;
89 } 180 }
90 181
91 ob = evas_outbuf_new(info, 182 ob = evas_outbuf_new(info,
92 e->output.w, 183 e->output.w,
93 e->output.h); 184 e->output.h);
94 if (EINA_UNLIKELY(!ob)) 185 if (EINA_UNLIKELY(!ob))
95 { 186 {
96 CRI("Failed to create outbuf"); 187 CRI("Failed to create outbuf");
97 goto err; 188 goto err;
98 } 189 }
99 re->win = ob; // FIXME REMVOE ME 190
100 ob->evas = evas; 191 ob->evas = evas;
101 info->view = ob->ns_gl_view; 192 info->view = ob->ns_gl_view;
193
194 chk = evas_render_engine_gl_generic_init(&re->generic, ob,
195 evas_outbuf_buffer_state_get,
196 evas_outbuf_rot_get,
197 evas_outbuf_reconfigure,
198 evas_outbuf_update_region_first_rect,
199 NULL,
200 evas_outbuf_update_region_new,
201 evas_outbuf_update_region_push,
202 evas_outbuf_update_region_free,
203 NULL,
204 evas_outbuf_flush,
205 evas_outbuf_free,
206 evas_outbuf_use,
207 evas_outbuf_gl_context_get,
208 evas_outbuf_egl_display_get,
209 evas_outbuf_gl_context_new,
210 evas_outbuf_gl_context_use,
211 &evgl_funcs, ob->w, ob->h);
212 if (EINA_UNLIKELY(!ob))
213 {
214 CRI("Failed to initialize gl_generic");
215 evas_outbuf_free(re->win);
216 goto err;
217 }
218 re->win = ob;
102 e->engine.data.output = re; 219 e->engine.data.output = re;
220 _gl_wins++;
103 } 221 }
104 else 222 else
105 { 223 {
106 re = e->engine.data.output; 224 CRI("ALREADY A DATA OUTPUT. THIS PART IS NOT IMPLEMENTED YET. PLEASE REPORT.");
107 evas_outbuf_free(re->win); 225 return 0;
108 re->win = evas_outbuf_new(info, 226 }
109 e->output.w, 227 if (EINA_UNLIKELY(!e->engine.data.output))
110 e->output.h); 228 {
111 info->view = re->win->ns_gl_view; 229 CRI("Failed to create a data output");
230 return 0;
112 } 231 }
113 if (!e->engine.data.output) return 0;
114 232
115 if (!e->engine.data.context) 233 if (!e->engine.data.context)
116 e->engine.data.context = 234 e->engine.data.context =
@@ -126,1184 +244,63 @@ err:
126static void 244static void
127eng_output_free(void *data) 245eng_output_free(void *data)
128{ 246{
129 Render_Engine *re; 247 Render_Engine *const re = data;
130 248
131 DBG("Output free");
132 re = (Render_Engine *)data;
133 evas_outbuf_free(re->win); 249 evas_outbuf_free(re->win);
134 free(re); 250 free(re);
135 251
136 if (_initted) 252 _gl_wins--;
253 if (_initted && (_gl_wins == 0))
137 { 254 {
138 // TODO gl_preload_shutdown 255 glsym_evas_gl_preload_shutdown();
139 evas_common_shutdown(); 256 evas_common_shutdown();
140 _initted = EINA_FALSE; 257 _initted = EINA_FALSE;
141 } 258 }
142} 259}
143 260
144static void
145eng_output_resize(void *data, int w, int h)
146{
147 Render_Engine *re;
148
149 DBG("Output Resize %d %d", w, h);
150
151 re = (Render_Engine *)data;
152 re->win->width = w;
153 re->win->height = h;
154
155 evas_gl_common_context_resize(re->win->gl_context, w, h, 0);
156 evas_outbuf_resize(re->win, w, h);
157}
158
159static void
160eng_output_tile_size_set(void *data EINA_UNUSED, int w EINA_UNUSED, int h EINA_UNUSED)
161{
162 DBG("tile size set");
163}
164
165static void
166eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
167{
168 Render_Engine *re;
169
170 DBG("Redraw rect %d %d %d %d", x, y, w, h);
171 re = (Render_Engine *)data;
172 evas_outbuf_lock_focus(re->win);
173 evas_gl_common_context_resize(re->win->gl_context, re->win->width, re->win->height, 0);
174 /* simple bounding box */
175 RECTS_CLIP_TO_RECT(x, y, w, h, 0, 0, re->win->width, re->win->height);
176 if ((w <= 0) || (h <= 0)) goto end;
177 if (!re->win->draw.redraw)
178 {
179#if 0
180 re->win->draw.x1 = x;
181 re->win->draw.y1 = y;
182 re->win->draw.x2 = x + w - 1;
183 re->win->draw.y2 = y + h - 1;
184#else
185 re->win->draw.x1 = 0;
186 re->win->draw.y1 = 0;
187 re->win->draw.x2 = re->win->width - 1;
188 re->win->draw.y2 = re->win->height - 1;
189#endif
190 }
191 else
192 {
193 if (x < re->win->draw.x1) re->win->draw.x1 = x;
194 if (y < re->win->draw.y1) re->win->draw.y1 = y;
195 if ((x + w - 1) > re->win->draw.x2) re->win->draw.x2 = x + w - 1;
196 if ((y + h - 1) > re->win->draw.y2) re->win->draw.y2 = y + h - 1;
197 }
198 re->win->draw.redraw = 1;
199end:
200 evas_outbuf_unlock_focus(re->win);
201}
202
203static void
204eng_output_redraws_rect_del(void *data EINA_UNUSED, int x EINA_UNUSED, int y EINA_UNUSED, int w EINA_UNUSED, int h EINA_UNUSED)
205{
206}
207
208static void
209eng_output_redraws_clear(void *data)
210{
211 Render_Engine *re;
212
213 re = (Render_Engine *)data;
214 re->win->draw.redraw = 0;
215}
216
217//#define SLOW_GL_COPY_RECT 1
218/* vsync games - not for now though */
219#define VSYNC_TO_SCREEN 1
220
221static void *
222eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
223{
224 Render_Engine *re;
225
226 re = (Render_Engine *)data;
227 evas_gl_common_context_flush(re->win->gl_context);
228 evas_gl_common_context_newframe(re->win->gl_context);
229 /* get the upate rect surface - return engine data as dummy */
230 if (!re->win->draw.redraw)
231 {
232 // printf("GL: NO updates!\n");
233 return NULL;
234 }
235 // printf("GL: update....!\n");
236#ifdef SLOW_GL_COPY_RECT
237 /* if any update - just return the whole canvas - works with swap
238 * buffers then */
239 if (x) *x = 0;
240 if (y) *y = 0;
241 if (w) *w = re->win->width;
242 if (h) *h = re->win->height;
243 if (cx) *cx = 0;
244 if (cy) *cy = 0;
245 if (cw) *cw = re->win->width;
246 if (ch) *ch = re->win->height;
247#else
248 /* 1 update - INCREDIBLY SLOW if combined with swap_rect in flush. a gl
249 * problem where there just is no hardware path for somethnig that
250 * obviously SHOULD be there */
251 /* only 1 update to minimise gl context games and rendering multiple update
252 * regions as evas does with other engines
253 */
254 if (x) *x = re->win->draw.x1;
255 if (y) *y = re->win->draw.y1;
256 if (w) *w = re->win->draw.x2 - re->win->draw.x1 + 1;
257 if (h) *h = re->win->draw.y2 - re->win->draw.y1 + 1;
258 if (cx) *cx = re->win->draw.x1;
259 if (cy) *cy = re->win->draw.y1;
260 if (cw) *cw = re->win->draw.x2 - re->win->draw.x1 + 1;
261 if (ch) *ch = re->win->draw.y2 - re->win->draw.y1 + 1;
262#endif
263 // clear buffer. only needed for dest alpha
264 // glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
265 // glClear(GL_COLOR_BUFFER_BIT);
266 //x// printf("frame -> new\n");
267 return re->win->gl_context->def_surface;
268}
269
270static void
271eng_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)
272{
273 Render_Engine *re;
274
275 if (render_mode == EVAS_RENDER_MODE_ASYNC_INIT) return;
276
277 re = (Render_Engine *)data;
278 /* put back update surface.. in this case just unflag redraw */
279 re->win->draw.redraw = 0;
280 re->win->draw.drew = 1;
281 evas_gl_common_context_flush(re->win->gl_context);
282}
283
284static void
285eng_output_flush(void *data, Evas_Render_Mode render_mode)
286{
287 Render_Engine *re;
288
289 if (render_mode == EVAS_RENDER_MODE_ASYNC_INIT) return;
290
291 re = (Render_Engine *)data;
292 if (!re->win->draw.drew) return;
293
294 re->win->draw.drew = 0;
295 evas_outbuf_use(re->win);
296
297#ifdef VSYNC_TO_SCREEN
298 evas_outbuf_vsync_set(1);
299#endif
300 evas_outbuf_lock_focus(re->win);
301 evas_outbuf_swap_buffers(re->win);
302 evas_outbuf_unlock_focus(re->win);
303}
304
305static void
306eng_context_cutout_add(void *data EINA_UNUSED, void *context, int x, int y, int w, int h)
307{
308 evas_common_draw_context_add_cutout(context, x, y, w, h);
309}
310
311static void
312eng_context_cutout_clear(void *data EINA_UNUSED, void *context)
313{
314 evas_common_draw_context_clear_cutouts(context);
315}
316
317static void
318eng_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h, Eina_Bool do_async EINA_UNUSED)
319{
320 Render_Engine *re;
321
322 re = (Render_Engine *)data;
323 evas_outbuf_use(re->win);
324 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
325 re->win->gl_context->dc = context;
326 evas_gl_common_rect_draw(re->win->gl_context, x, y, w, h);
327}
328
329static void
330eng_line_draw(void *data, void *context, void *surface, int p1x, int p1y, int p2x, int p2y, Eina_Bool do_async EINA_UNUSED)
331{
332 Render_Engine *re;
333
334 re = (Render_Engine *)data;
335 evas_outbuf_use(re->win);
336 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
337 re->win->gl_context->dc = context;
338 evas_gl_common_line_draw(re->win->gl_context, p1x, p1y, p2x, p2y);
339}
340
341static void *
342eng_polygon_point_add(void *data, void *context EINA_UNUSED, void *polygon, int x, int y)
343{
344 Render_Engine *re;
345
346 re = (Render_Engine *)data;
347 return evas_gl_common_poly_point_add(polygon, x, y);
348}
349
350static void *
351eng_polygon_points_clear(void *data, void *context EINA_UNUSED, void *polygon)
352{
353 Render_Engine *re;
354
355 re = (Render_Engine *)data;
356 return evas_gl_common_poly_points_clear(polygon);
357}
358
359static void
360eng_polygon_draw(void *data, void *context, void *surface EINA_UNUSED, void *polygon, int x, int y, Eina_Bool do_async EINA_UNUSED)
361{
362 Render_Engine *re;
363
364 re = (Render_Engine *)data;
365 evas_outbuf_use(re->win);
366 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
367 re->win->gl_context->dc = context;
368 evas_gl_common_poly_draw(re->win->gl_context, polygon, x, y);
369}
370
371static int
372eng_image_alpha_get(void *data EINA_UNUSED, void *image)
373{
374 Evas_GL_Image *im;
375
376 if (!image) return 1;
377 im = image;
378 return im->alpha;
379}
380
381static Evas_Colorspace
382eng_image_colorspace_get(void *data EINA_UNUSED, void *image)
383{
384 Evas_GL_Image *im;
385
386 if (!image) return EVAS_COLORSPACE_ARGB8888;
387 im = image;
388 return im->cs.space;
389}
390
391static void *
392eng_image_alpha_set(void *data, void *image, int has_alpha)
393{
394 Render_Engine *re;
395 Evas_GL_Image *im;
396
397 re = (Render_Engine *)data;
398 if (!image) return NULL;
399 im = image;
400 if (im->alpha == has_alpha) return image;
401 if (im->native.data)
402 {
403 im->alpha = has_alpha;
404 return image;
405 }
406 evas_outbuf_use(re->win);
407 if ((im->tex) && (im->tex->pt->dyn.img))
408 {
409 im->alpha = has_alpha;
410 im->tex->alpha = im->alpha;
411 return image;
412 }
413 /* FIXME: can move to gl_common */
414 if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im;
415 if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image;
416 else if ((!has_alpha) && (!im->im->cache_entry.flags.alpha)) return image;
417 if (im->references > 1)
418 {
419 Evas_GL_Image *im_new;
420
421 if (!im->im->image.data)
422 evas_cache_image_load_data(&im->im->cache_entry);
423 evas_gl_common_image_alloc_ensure(im);
424 im_new = evas_gl_common_image_new_from_copied_data
425 (im->gc, im->im->cache_entry.w, im->im->cache_entry.h,
426 im->im->image.data,
427 eng_image_alpha_get(data, image),
428 eng_image_colorspace_get(data, image));
429 if (!im_new) return im;
430 evas_gl_common_image_free(im);
431 im = im_new;
432 }
433 else
434 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
435 return evas_gl_common_image_alpha_set(im, has_alpha ? 1 : 0);
436 // im->im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
437 // return image;
438}
439
440static Evas_Colorspace
441eng_image_file_colorspace_get(void *data EINA_UNUSED, void *image)
442{
443 Evas_GL_Image *im = image;
444
445 if (!im || !im->im) return EVAS_COLORSPACE_ARGB8888;
446 if (im->im->cache_entry.cspaces)
447 return im->im->cache_entry.cspaces[0];
448 return im->im->cache_entry.space;
449}
450
451static void *
452eng_image_data_direct(void *data EINA_UNUSED, void *image, Evas_Colorspace *cspace)
453{
454 Evas_GL_Image *im = image;
455
456 if (!im || !im->im) return NULL;
457 if (cspace) *cspace = im->im->cache_entry.space;
458 return im->im->image.data;
459}
460
461static void
462eng_image_colorspace_set(void *data, void *image, Evas_Colorspace cspace)
463{
464 Render_Engine *re;
465 Evas_GL_Image *im;
466
467 re = (Render_Engine *)data;
468 if (!image) return;
469 im = image;
470 if (im->native.data) return;
471 /* FIXME: can move to gl_common */
472 if (im->cs.space == cspace) return;
473 evas_outbuf_use(re->win);
474 evas_gl_common_image_alloc_ensure(im);
475 evas_cache_image_colorspace(&im->im->cache_entry, cspace);
476 switch (cspace)
477 {
478 case EVAS_COLORSPACE_ARGB8888:
479 if (im->cs.data)
480 {
481 if (!im->cs.no_free) free(im->cs.data);
482 im->cs.data = NULL;
483 im->cs.no_free = 0;
484 }
485 break;
486 case EVAS_COLORSPACE_YCBCR422P601_PL:
487 case EVAS_COLORSPACE_YCBCR422P709_PL:
488 case EVAS_COLORSPACE_YCBCR422601_PL:
489 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
490 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
491 if (im->tex) evas_gl_common_texture_free(im->tex, EINA_TRUE);
492 im->tex = NULL;
493 if (im->cs.data)
494 {
495 if (!im->cs.no_free) free(im->cs.data);
496 }
497 if (im->im->cache_entry.h > 0)
498 im->cs.data =
499 calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
500 else
501 im->cs.data = NULL;
502 im->cs.no_free = 0;
503 break;
504 default:
505 abort();
506 break;
507 }
508 im->cs.space = cspace;
509}
510
511/////////////////////////////////////////////////////////////////////////
512//
513//
514
515// FIXME: this is enabled so updates happen - but its SLOOOOOOOOOOOOOOOW
516// (i am sure this is the reason) not to mention seemingly superfluous. but
517// i need to enable it for it to work on fglrx at least. havent tried nvidia.
518//
519// why is this the case? does anyone know? has anyone tried it on other gfx
520// drivers?
521//
522//#define GLX_TEX_PIXMAP_RECREATE 1
523
524//
525//
526/////////////////////////////////////////////////////////////////////////
527
528static void *
529eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
530{
531 Render_Engine *re;
532
533 re = (Render_Engine *)data;
534 *error = EVAS_LOAD_ERROR_NONE;
535 evas_outbuf_use(re->win);
536 return evas_gl_common_image_load(re->win->gl_context, file, key, lo, error);
537}
538
539static void *
540eng_image_mmap(void *data, Eina_File *f, const char *key, int *error, Evas_Image_Load_Opts *lo)
541{
542 Render_Engine *re;
543
544 re = (Render_Engine *)data;
545 *error = EVAS_LOAD_ERROR_NONE;
546 evas_outbuf_use(re->win);
547 return evas_gl_common_image_mmap(re->win->gl_context, f, key, lo, error);
548}
549
550static void *
551eng_image_new_from_data(void *data, int w, int h, DATA32 *image_data, int alpha, Evas_Colorspace cspace)
552{
553 Render_Engine *re;
554
555 re = (Render_Engine *)data;
556 evas_outbuf_use(re->win);
557 return evas_gl_common_image_new_from_data(re->win->gl_context, w, h, image_data, alpha, cspace);
558}
559
560static void *
561eng_image_new_from_copied_data(void *data, int w, int h, DATA32 *image_data, int alpha, Evas_Colorspace cspace)
562{
563 Render_Engine *re;
564
565 re = (Render_Engine *)data;
566 evas_outbuf_use(re->win);
567 return evas_gl_common_image_new_from_copied_data(re->win->gl_context, w, h, image_data, alpha, cspace);
568}
569
570static void
571eng_image_free(void *data, void *image)
572{
573 Render_Engine *re;
574
575 re = (Render_Engine *)data;
576 if (!image) return;
577 evas_outbuf_use(re->win);
578 evas_gl_common_image_unref(image);
579}
580
581static void
582eng_image_size_get(void *data EINA_UNUSED, void *image, int *w, int *h)
583{
584 if (!image)
585 {
586 *w = 0;
587 *h = 0;
588 return;
589 }
590 if (w) *w = ((Evas_GL_Image *)image)->w;
591 if (h) *h = ((Evas_GL_Image *)image)->h;
592}
593
594static void *
595eng_image_size_set(void *data, void *image, int w, int h)
596{
597 Render_Engine *re;
598 Evas_GL_Image *im = image;
599 Evas_GL_Image *im_old;
600
601 re = (Render_Engine *)data;
602 if (!im) return NULL;
603 if (im->native.data)
604 {
605 im->w = w;
606 im->h = h;
607 return image;
608 }
609 evas_outbuf_use(re->win);
610 if ((im->tex) && (im->tex->pt->dyn.img))
611 {
612 evas_gl_common_texture_free(im->tex, EINA_TRUE);
613 im->tex = NULL;
614 im->w = w;
615 im->h = h;
616 im->tex = evas_gl_common_texture_dynamic_new(im->gc, im);
617 return image;
618 }
619 im_old = image;
620
621 switch (eng_image_colorspace_get(data, image))
622 {
623 case EVAS_COLORSPACE_YCBCR422P601_PL:
624 case EVAS_COLORSPACE_YCBCR422P709_PL:
625 case EVAS_COLORSPACE_YCBCR422601_PL:
626 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
627 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
628 w &= ~0x1;
629 default:
630 break;
631 }
632
633 evas_gl_common_image_alloc_ensure(im_old);
634 if ((im_old->im) &&
635 ((int)im_old->im->cache_entry.w == w) &&
636 ((int)im_old->im->cache_entry.h == h))
637 return image;
638
639 im = evas_gl_common_image_new(re->win->gl_context, w, h,
640 eng_image_alpha_get(data, image),
641 eng_image_colorspace_get(data, image));
642 evas_gl_common_image_free(im_old);
643
644 return im;
645}
646
647static void *
648eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
649{
650 Render_Engine *re;
651 Evas_GL_Image *im = image;
652
653 re = (Render_Engine *)data;
654 if (!image) return NULL;
655 if (im->native.data) return image;
656 evas_outbuf_use(re->win);
657 evas_gl_common_image_dirty(image, x, y, w, h);
658 return image;
659}
660
661static void *
662eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data, int *err, Eina_Bool *tofree EINA_UNUSED)
663{
664 Render_Engine *re;
665 Evas_GL_Image *im;
666 int error;
667
668 re = (Render_Engine *)data;
669 if (!image)
670 {
671 *image_data = NULL;
672 if (err) *err = EVAS_LOAD_ERROR_GENERIC;
673 return NULL;
674 }
675 im = image;
676 if (im->native.data)
677 {
678 *image_data = NULL;
679 if (err) *err = EVAS_LOAD_ERROR_NONE;
680 return im;
681 }
682 if ((im->tex) && (im->tex->pt) && (im->tex->pt->dyn.data))
683 {
684 *image_data = im->tex->pt->dyn.data;
685 if (err) *err = EVAS_LOAD_ERROR_NONE;
686 return im;
687 }
688 evas_outbuf_use(re->win);
689 error = evas_cache_image_load_data(&im->im->cache_entry);
690 evas_gl_common_image_alloc_ensure(im);
691 switch (im->cs.space)
692 {
693 case EVAS_COLORSPACE_ARGB8888:
694 if (to_write)
695 {
696 if (im->references > 1)
697 {
698 Evas_GL_Image *im_new;
699
700 im_new = evas_gl_common_image_new_from_copied_data
701 (im->gc, im->im->cache_entry.w, im->im->cache_entry.h,
702 im->im->image.data,
703 eng_image_alpha_get(data, image),
704 eng_image_colorspace_get(data, image));
705 if (!im_new)
706 {
707 *image_data = NULL;
708 if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
709 return im;
710 }
711 evas_gl_common_image_free(im);
712 im = im_new;
713 }
714 else
715 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
716 }
717 *image_data = im->im->image.data;
718 break;
719 case EVAS_COLORSPACE_YCBCR422P601_PL:
720 case EVAS_COLORSPACE_YCBCR422P709_PL:
721 case EVAS_COLORSPACE_YCBCR422601_PL:
722 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
723 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
724 *image_data = im->cs.data;
725 break;
726 default:
727 abort();
728 break;
729 }
730 if (err) *err = error;
731 return im;
732}
733
734static void *
735eng_image_data_put(void *data, void *image, DATA32 *image_data)
736{
737 Render_Engine *re;
738 Evas_GL_Image *im, *im2;
739
740 re = (Render_Engine *)data;
741 if (!image) return NULL;
742 im = image;
743 if (im->native.data) return image;
744 evas_outbuf_use(re->win);
745 evas_gl_common_image_alloc_ensure(im);
746 if ((im->tex) && (im->tex->pt) && (im->tex->pt->dyn.data))
747 {
748 if (im->tex->pt->dyn.data == image_data)
749 {
750 return image;
751 }
752 else
753 {
754 int w, h;
755
756 w = im->im->cache_entry.w;
757 h = im->im->cache_entry.h;
758 im2 = eng_image_new_from_data(data, w, h, image_data,
759 eng_image_alpha_get(data, image),
760 eng_image_colorspace_get(data, image));
761 if (!im2) return im;
762 evas_gl_common_image_free(im);
763 im = im2;
764 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
765 return im;
766 }
767 }
768 switch (im->cs.space)
769 {
770 case EVAS_COLORSPACE_ARGB8888:
771 if (image_data != im->im->image.data)
772 {
773 int w, h;
774
775 w = im->im->cache_entry.w;
776 h = im->im->cache_entry.h;
777 im2 = eng_image_new_from_data(data, w, h, image_data,
778 eng_image_alpha_get(data, image),
779 eng_image_colorspace_get(data, image));
780 if (!im2) return im;
781 evas_gl_common_image_free(im);
782 im = im2;
783 }
784 break;
785 case EVAS_COLORSPACE_YCBCR422P601_PL:
786 case EVAS_COLORSPACE_YCBCR422P709_PL:
787 if (image_data != im->cs.data)
788 {
789 if (im->cs.data)
790 {
791 if (!im->cs.no_free) free(im->cs.data);
792 }
793 im->cs.data = image_data;
794 }
795 break;
796 default:
797 abort();
798 break;
799 }
800 /* hmmm - but if we wrote... why bother? */
801 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
802 return im;
803}
804
805static void
806eng_image_data_preload_request(void *data EINA_UNUSED, void *image, const Eo *target)
807{
808 Evas_GL_Image *gim = image;
809 RGBA_Image *im;
810
811 if (!gim) return;
812 if (gim->native.data) return;
813 im = (RGBA_Image *)gim->im;
814 if (!im) return;
815 evas_cache_image_preload_data(&im->cache_entry, target, NULL, NULL, NULL);
816}
817
818static void
819eng_image_data_preload_cancel(void *data EINA_UNUSED, void *image, const Eo *target)
820{
821 Evas_GL_Image *gim = image;
822 RGBA_Image *im;
823
824 if (!gim) return;
825 if (gim->native.data) return;
826 im = (RGBA_Image *)gim->im;
827 if (!im) return;
828 evas_cache_image_preload_cancel(&im->cache_entry, target);
829}
830
831static Eina_Bool
832eng_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)
833{
834 Render_Engine *re;
835
836 re = (Render_Engine *)data;
837 if (!image) return EINA_FALSE;
838 evas_outbuf_use(re->win);
839 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
840 re->win->gl_context->dc = context;
841 evas_gl_common_image_draw(re->win->gl_context, image,
842 src_x, src_y, src_w, src_h,
843 dst_x, dst_y, dst_w, dst_h,
844 smooth);
845 return EINA_FALSE;
846}
847
848static void
849eng_image_scale_hint_set(void *data EINA_UNUSED, void *image, int hint)
850{
851 if (image) evas_gl_common_image_scale_hint_set(image, hint);
852}
853
854static int
855eng_image_scale_hint_get(void *data EINA_UNUSED, void *image)
856{
857 Evas_GL_Image *gim = image;
858 if (!gim) return EVAS_IMAGE_SCALE_HINT_NONE;
859 return gim->scale_hint;
860}
861
862static Eina_Bool
863eng_image_map_draw(void *data, void *context, void *surface, void *image, RGBA_Map *m, int smooth, int level, Eina_Bool do_async)
864{
865 Evas_GL_Image *gim = image;
866 Render_Engine *re;
867
868 re = (Render_Engine *)data;
869 if (!image) return EINA_FALSE;
870 evas_outbuf_use(re->win);
871 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
872 re->win->gl_context->dc = context;
873 if (m->count != 4)
874 {
875 // FIXME: nash - you didn't fix this
876 abort();
877 }
878 if ((m->pts[0].x == m->pts[3].x) &&
879 (m->pts[1].x == m->pts[2].x) &&
880 (m->pts[0].y == m->pts[1].y) &&
881 (m->pts[3].y == m->pts[2].y) &&
882 (m->pts[0].x <= m->pts[1].x) &&
883 (m->pts[0].y <= m->pts[2].y) &&
884 (m->pts[0].u == 0) &&
885 (m->pts[0].v == 0) &&
886 (m->pts[1].u == (gim->w << FP)) &&
887 (m->pts[1].v == 0) &&
888 (m->pts[2].u == (gim->w << FP)) &&
889 (m->pts[2].v == (gim->h << FP)) &&
890 (m->pts[3].u == 0) &&
891 (m->pts[3].v == (gim->h << FP)) &&
892 (m->pts[0].col == 0xffffffff) &&
893 (m->pts[1].col == 0xffffffff) &&
894 (m->pts[2].col == 0xffffffff) &&
895 (m->pts[3].col == 0xffffffff))
896 {
897 int dx, dy, dw, dh;
898
899 dx = m->pts[0].x >> FP;
900 dy = m->pts[0].y >> FP;
901 dw = (m->pts[2].x >> FP) - dx;
902 dh = (m->pts[2].y >> FP) - dy;
903 eng_image_draw(data, context, surface, image,
904 0, 0, gim->w, gim->h, dx, dy, dw, dh, smooth, do_async);
905 }
906 else
907 {
908 evas_gl_common_image_map_draw(re->win->gl_context, image, m->count, &m->pts[0],
909 smooth, level);
910 }
911
912 return EINA_FALSE;
913}
914
915static void *
916eng_image_map_surface_new(void *data EINA_UNUSED, int w, int h, int alpha)
917{
918 Render_Engine *re;
919
920 re = (Render_Engine *)data;
921 return evas_gl_common_image_surface_new(re->win->gl_context, w, h, alpha);
922}
923
924static void
925eng_image_content_hint_set(void *data, void *image, int hint)
926{
927 Render_Engine *re;
928 re = (Render_Engine *)data;
929
930 if (re) evas_outbuf_use(re->win);
931 if (image) evas_gl_common_image_content_hint_set(image, hint);
932}
933
934static int
935eng_image_content_hint_get(void *data EINA_UNUSED, void *image)
936{
937 Evas_GL_Image *gim = image;
938 if (!gim) return EVAS_IMAGE_CONTENT_HINT_NONE;
939 return gim->content_hint;
940}
941
942static void
943eng_image_cache_flush(void *data EINA_UNUSED)
944{
945 Render_Engine *re;
946 int tmp_size;
947
948 re = (Render_Engine *)data;
949
950 tmp_size = evas_common_image_get_cache();
951 evas_common_image_set_cache(0);
952 evas_common_rgba_image_scalecache_flush();
953 evas_gl_common_image_cache_flush(re->win->gl_context);
954 evas_common_image_set_cache(tmp_size);
955}
956
957static void
958eng_image_cache_set(void *data EINA_UNUSED, int bytes)
959{
960 Render_Engine *re;
961
962 re = (Render_Engine *)data;
963 evas_common_image_set_cache(bytes);
964 evas_common_rgba_image_scalecache_size_set(bytes);
965 evas_gl_common_image_cache_flush(re->win->gl_context);
966}
967
968static int
969eng_image_cache_get(void *data EINA_UNUSED)
970{
971 Render_Engine *re;
972
973 re = (Render_Engine *)data;
974 return evas_common_image_get_cache();
975}
976
977
978static void
979eng_image_stride_get(void *data EINA_UNUSED, void *image, int *stride)
980{
981 Evas_GL_Image *im = image;
982 *stride = im->w * 4;
983 if ((im->tex) && (im->tex->pt->dyn.img))
984 {
985 *stride = im->tex->pt->dyn.w * 4;
986 // FIXME: for other image formats (yuv etc.) different stride needed
987 }
988}
989
990static Eina_Bool
991eng_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)
992{
993 Render_Engine *re = data;
994 evas_outbuf_use(re->win);
995
996 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
997 re->win->gl_context->dc = context;
998 {
999 if (!re->win->gl_context->font_surface)
1000 re->win->gl_context->font_surface = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
1001 re->win->gl_context->font_surface->cache_entry.w = re->win->gl_context->shared->w;
1002 re->win->gl_context->font_surface->cache_entry.h = re->win->gl_context->shared->h;
1003
1004 evas_common_draw_context_font_ext_set(context,
1005 re->win->gl_context,
1006 evas_gl_font_texture_new,
1007 evas_gl_font_texture_free,
1008 evas_gl_font_texture_draw,
1009 NULL,
1010 NULL,
1011 NULL);
1012 evas_common_font_draw_prepare(intl_props);
1013 evas_common_font_draw(re->win->gl_context->font_surface, context, x, y, intl_props->glyphs);
1014 evas_common_draw_context_font_ext_set(context,
1015 NULL,
1016 NULL,
1017 NULL,
1018 NULL,
1019 NULL,
1020 NULL,
1021 NULL);
1022 }
1023
1024 return EINA_FALSE;
1025}
1026
1027
1028static Eina_Bool 261static Eina_Bool
1029eng_canvas_alpha_get(void *data EINA_UNUSED, void *info EINA_UNUSED) 262eng_canvas_alpha_get(void *data EINA_UNUSED, void *info EINA_UNUSED)
1030{ 263{
1031 // FIXME: support ARGB gl targets!!! 264 return EINA_TRUE;
1032 return EINA_FALSE;
1033}
1034
1035
1036#if 1
1037static void
1038evgl_glBindFramebuffer(GLenum target, GLuint framebuffer)
1039{
1040 // Add logic to take care when framebuffer=0
1041 glBindFramebuffer(target, framebuffer);
1042}
1043
1044static void
1045evgl_glBindRenderbuffer(GLenum target, GLuint renderbuffer)
1046{
1047 // Add logic to take care when renderbuffer=0
1048 glBindRenderbuffer(target, renderbuffer);
1049}
1050
1051static void
1052evgl_glClearDepthf(GLclampf depth)
1053{
1054#ifdef GL_GLES
1055 glClearDepthf(depth);
1056#else
1057 glClearDepth(depth);
1058#endif
1059}
1060
1061static void
1062evgl_glDepthRangef(GLclampf zNear, GLclampf zFar)
1063{
1064#ifdef GL_GLES
1065 glDepthRangef(zNear, zFar);
1066#else
1067 glDepthRange(zNear, zFar);
1068#endif
1069}
1070
1071static void
1072evgl_glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
1073{
1074#ifdef GL_GLES
1075 glGetShaderPrecisionFormat(shadertype, precisiontype, range, precision);
1076#else
1077 if (range)
1078 {
1079 range[0] = -126; // floor(log2(FLT_MIN))
1080 range[1] = 127; // floor(log2(FLT_MAX))
1081 }
1082 if (precision)
1083 {
1084 precision[0] = 24; // floor(-log2((1.0/16777218.0)));
1085 }
1086 return;
1087 shadertype = precisiontype = 0;
1088#endif
1089}
1090
1091static void
1092evgl_glReleaseShaderCompiler(void)
1093{
1094#ifdef GL_GLES
1095 glReleaseShaderCompiler();
1096#else
1097#endif
1098} 265}
1099 266
1100static void 267static void
1101evgl_glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length) 268_gl_symbols(void)
1102{ 269{
1103#ifdef GL_GLES 270 static Eina_Bool done = EINA_FALSE;
1104 glShaderBinary(n, shaders, binaryformat, binary, length);
1105#else
1106 // FIXME: need to dlsym/getprocaddress for this
1107 return;
1108 n = binaryformat = length = 0;
1109 shaders = binary = 0;
1110#endif
1111}
1112 271
1113#endif 272 if (done) return;
1114 273
1115static void 274#define LINK2GENERIC(sym) \
1116eng_output_idle_flush(void *data EINA_UNUSED) 275 glsym_##sym = dlsym(RTLD_DEFAULT, #sym);
1117{
1118}
1119
1120static void *
1121eng_gl_api_get(void *data, int version EINA_UNUSED)
1122{
1123 Render_Engine *re;
1124
1125 re = (Render_Engine *)data;
1126 276
1127 gl_funcs.version = EVAS_GL_API_VERSION; 277 LINK2GENERIC(evas_gl_common_context_new);
1128#if 1 278 LINK2GENERIC(evas_gl_common_context_flush);
1129#define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, ) 279 LINK2GENERIC(evas_gl_common_context_free);
1130 ORD(glActiveTexture); 280 LINK2GENERIC(evas_gl_common_context_use);
1131 ORD(glAttachShader); 281 LINK2GENERIC(evas_gl_common_context_done);
1132 ORD(glBindAttribLocation); 282 LINK2GENERIC(evas_gl_common_context_resize);
1133 ORD(glBindBuffer); 283 LINK2GENERIC(evas_gl_common_context_newframe);
1134 ORD(glBindTexture); 284 LINK2GENERIC(evas_gl_preload_render_lock);
1135 ORD(glBlendColor); 285 LINK2GENERIC(evas_gl_preload_render_unlock);
1136 ORD(glBlendEquation); 286 LINK2GENERIC(evas_gl_preload_init);
1137 ORD(glBlendEquationSeparate); 287 LINK2GENERIC(evas_gl_preload_shutdown);
1138 ORD(glBlendFunc);
1139 ORD(glBlendFuncSeparate);
1140 ORD(glBufferData);
1141 ORD(glBufferSubData);
1142 ORD(glCheckFramebufferStatus);
1143 ORD(glClear);
1144 ORD(glClearColor);
1145 // ORD(glClearDepthf);
1146 ORD(glClearStencil);
1147 ORD(glColorMask);
1148 ORD(glCompileShader);
1149 ORD(glCompressedTexImage2D);
1150 ORD(glCompressedTexSubImage2D);
1151 ORD(glCopyTexImage2D);
1152 ORD(glCopyTexSubImage2D);
1153 ORD(glCreateProgram);
1154 ORD(glCreateShader);
1155 ORD(glCullFace);
1156 ORD(glDeleteBuffers);
1157 ORD(glDeleteFramebuffers);
1158 ORD(glDeleteProgram);
1159 ORD(glDeleteRenderbuffers);
1160 ORD(glDeleteShader);
1161 ORD(glDeleteTextures);
1162 ORD(glDepthFunc);
1163 ORD(glDepthMask);
1164 // ORD(glDepthRangef);
1165 ORD(glDetachShader);
1166 ORD(glDisable);
1167 ORD(glDisableVertexAttribArray);
1168 ORD(glDrawArrays);
1169 ORD(glDrawElements);
1170 ORD(glEnable);
1171 ORD(glEnableVertexAttribArray);
1172 ORD(glFinish);
1173 ORD(glFlush);
1174 ORD(glFramebufferRenderbuffer);
1175 ORD(glFramebufferTexture2D);
1176 ORD(glFrontFace);
1177 ORD(glGenBuffers);
1178 ORD(glGenerateMipmap);
1179 ORD(glGenFramebuffers);
1180 ORD(glGenRenderbuffers);
1181 ORD(glGenTextures);
1182 ORD(glGetActiveAttrib);
1183 ORD(glGetActiveUniform);
1184 ORD(glGetAttachedShaders);
1185 ORD(glGetAttribLocation);
1186 ORD(glGetBooleanv);
1187 ORD(glGetBufferParameteriv);
1188 ORD(glGetError);
1189 ORD(glGetFloatv);
1190 ORD(glGetFramebufferAttachmentParameteriv);
1191 ORD(glGetIntegerv);
1192 ORD(glGetProgramiv);
1193 ORD(glGetProgramInfoLog);
1194 ORD(glGetRenderbufferParameteriv);
1195 ORD(glGetShaderiv);
1196 ORD(glGetShaderInfoLog);
1197 // ORD(glGetShaderPrecisionFormat);
1198 ORD(glGetShaderSource);
1199 ORD(glGetString);
1200 ORD(glGetTexParameterfv);
1201 ORD(glGetTexParameteriv);
1202 ORD(glGetUniformfv);
1203 ORD(glGetUniformiv);
1204 ORD(glGetUniformLocation);
1205 ORD(glGetVertexAttribfv);
1206 ORD(glGetVertexAttribiv);
1207 ORD(glGetVertexAttribPointerv);
1208 ORD(glHint);
1209 ORD(glIsBuffer);
1210 ORD(glIsEnabled);
1211 ORD(glIsFramebuffer);
1212 ORD(glIsProgram);
1213 ORD(glIsRenderbuffer);
1214 ORD(glIsShader);
1215 ORD(glIsTexture);
1216 ORD(glLineWidth);
1217 ORD(glLinkProgram);
1218 ORD(glPixelStorei);
1219 ORD(glPolygonOffset);
1220 ORD(glReadPixels);
1221 // ORD(glReleaseShaderCompiler);
1222 ORD(glRenderbufferStorage);
1223 ORD(glSampleCoverage);
1224 ORD(glScissor);
1225 // ORD(glShaderBinary);
1226 ORD(glShaderSource);
1227 ORD(glStencilFunc);
1228 ORD(glStencilFuncSeparate);
1229 ORD(glStencilMask);
1230 ORD(glStencilMaskSeparate);
1231 ORD(glStencilOp);
1232 ORD(glStencilOpSeparate);
1233 ORD(glTexImage2D);
1234 ORD(glTexParameterf);
1235 ORD(glTexParameterfv);
1236 ORD(glTexParameteri);
1237 ORD(glTexParameteriv);
1238 ORD(glTexSubImage2D);
1239 ORD(glUniform1f);
1240 ORD(glUniform1fv);
1241 ORD(glUniform1i);
1242 ORD(glUniform1iv);
1243 ORD(glUniform2f);
1244 ORD(glUniform2fv);
1245 ORD(glUniform2i);
1246 ORD(glUniform2iv);
1247 ORD(glUniform3f);
1248 ORD(glUniform3fv);
1249 ORD(glUniform3i);
1250 ORD(glUniform3iv);
1251 ORD(glUniform4f);
1252 ORD(glUniform4fv);
1253 ORD(glUniform4i);
1254 ORD(glUniform4iv);
1255 ORD(glUniformMatrix2fv);
1256 ORD(glUniformMatrix3fv);
1257 ORD(glUniformMatrix4fv);
1258 ORD(glUseProgram);
1259 ORD(glValidateProgram);
1260 ORD(glVertexAttrib1f);
1261 ORD(glVertexAttrib1fv);
1262 ORD(glVertexAttrib2f);
1263 ORD(glVertexAttrib2fv);
1264 ORD(glVertexAttrib3f);
1265 ORD(glVertexAttrib3fv);
1266 ORD(glVertexAttrib4f);
1267 ORD(glVertexAttrib4fv);
1268 ORD(glVertexAttribPointer);
1269 ORD(glViewport);
1270#undef ORD
1271 288
1272 // Override functions wrapped by Evas_GL 289 LINK2GENERIC(evas_gl_symbols);
1273#define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, evgl_)
1274 ORD(glBindFramebuffer);
1275 ORD(glBindRenderbuffer);
1276
1277 // GLES2.0 API compat on top of desktop gl
1278 ORD(glClearDepthf);
1279 ORD(glDepthRangef);
1280 ORD(glGetShaderPrecisionFormat);
1281 ORD(glReleaseShaderCompiler);
1282 ORD(glShaderBinary);
1283#undef ORD
1284 290
1285#endif 291#undef LINK2GENERIC
1286 292
1287 return &gl_funcs; 293 done = EINA_TRUE;
1288} 294}
1289 295
1290static int
1291eng_image_load_error_get(void *data EINA_UNUSED, void *image)
1292{
1293 Evas_GL_Image *im;
1294
1295 if (!image) return EVAS_LOAD_ERROR_NONE;
1296 im = image;
1297 return im->im->cache_entry.load_error;
1298}
1299 296
1300static int 297static int
1301module_open(Evas_Module *em) 298module_open(Evas_Module *em)
1302{ 299{
1303 if (!em) return 0; 300 if (!em) return 0;
1304 if (!evas_gl_common_module_open()) return 0; 301
1305 /* get whatever engine module we inherit from */ 302 /* get whatever engine module we inherit from */
1306 if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0; 303 if (!_evas_module_engine_inherit(&pfunc, "gl_generic")) return 0;
1307 304
1308 if (_evas_engine_gl_cocoa_log_dom < 0) 305 if (_evas_engine_gl_cocoa_log_dom < 0)
1309 { 306 {
@@ -1315,8 +312,10 @@ module_open(Evas_Module *em)
1315 return 0; 312 return 0;
1316 } 313 }
1317 } 314 }
315
1318 /* store it for later use */ 316 /* store it for later use */
1319 func = pfunc; 317 func = pfunc;
318
1320 /* now to override methods */ 319 /* now to override methods */
1321#define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_) 320#define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
1322 ORD(info); 321 ORD(info);
@@ -1324,75 +323,8 @@ module_open(Evas_Module *em)
1324 ORD(setup); 323 ORD(setup);
1325 ORD(canvas_alpha_get); 324 ORD(canvas_alpha_get);
1326 ORD(output_free); 325 ORD(output_free);
1327 ORD(output_resize);
1328 ORD(output_tile_size_set);
1329 ORD(output_redraws_rect_add);
1330 ORD(output_redraws_rect_del);
1331 ORD(output_redraws_clear);
1332 ORD(output_redraws_next_update_get);
1333 ORD(output_redraws_next_update_push);
1334 ORD(context_cutout_add);
1335 ORD(context_cutout_clear);
1336 ORD(output_flush);
1337 ORD(output_idle_flush);
1338 // ORD(output_dump);
1339 ORD(rectangle_draw);
1340 ORD(line_draw);
1341 ORD(polygon_point_add);
1342 ORD(polygon_points_clear);
1343 ORD(polygon_draw);
1344 326
1345 ORD(image_load); 327 _gl_symbols();
1346 ORD(image_mmap);
1347 ORD(image_new_from_data);
1348 ORD(image_new_from_copied_data);
1349 ORD(image_free);
1350 ORD(image_size_get);
1351 ORD(image_size_set);
1352 ORD(image_dirty_region);
1353 ORD(image_data_get);
1354 ORD(image_data_put);
1355 ORD(image_data_direct);
1356 ORD(image_data_preload_request);
1357 ORD(image_data_preload_cancel);
1358 ORD(image_alpha_set);
1359 ORD(image_alpha_get);
1360 ORD(image_draw);
1361 ORD(image_colorspace_set);
1362 ORD(image_colorspace_get);
1363 ORD(image_file_colorspace_get);
1364 // ORD(image_native_set);
1365 // ORD(image_native_get);
1366
1367 ORD(font_draw);
1368
1369 ORD(image_scale_hint_set);
1370 ORD(image_scale_hint_get);
1371 ORD(image_stride_get);
1372
1373 ORD(image_map_draw);
1374 ORD(image_map_surface_new);
1375
1376 ORD(image_content_hint_set);
1377 ORD(image_content_hint_get);
1378
1379 ORD(image_cache_flush);
1380 ORD(image_cache_set);
1381 ORD(image_cache_get);
1382
1383 ORD(gl_api_get);
1384
1385 ORD(image_load_error_get);
1386
1387#define LINK2GENERIC(sym) \
1388 glsym_##sym = dlsym(RTLD_DEFAULT, #sym);
1389
1390 LINK2GENERIC(evas_gl_common_context_new);
1391 LINK2GENERIC(evas_gl_common_context_flush);
1392 LINK2GENERIC(evas_gl_common_context_free);
1393 LINK2GENERIC(evas_gl_common_context_use);
1394 LINK2GENERIC(evas_gl_common_context_resize);
1395 LINK2GENERIC(evas_gl_symbols);
1396 328
1397 /* now advertise out own api */ 329 /* now advertise out own api */
1398 em->functions = (void *)(&func); 330 em->functions = (void *)(&func);
@@ -1407,7 +339,6 @@ module_close(Evas_Module *em EINA_UNUSED)
1407 eina_log_domain_unregister(_evas_engine_gl_cocoa_log_dom); 339 eina_log_domain_unregister(_evas_engine_gl_cocoa_log_dom);
1408 _evas_engine_gl_cocoa_log_dom = -1; 340 _evas_engine_gl_cocoa_log_dom = -1;
1409 } 341 }
1410 evas_gl_common_module_close();
1411} 342}
1412 343
1413static Evas_Module_Api evas_modapi = 344static Evas_Module_Api evas_modapi =
diff --git a/src/modules/evas/engines/gl_cocoa/evas_engine.h b/src/modules/evas/engines/gl_cocoa/evas_engine.h
index 9c7cbdd554..6e56809c40 100644
--- a/src/modules/evas/engines/gl_cocoa/evas_engine.h
+++ b/src/modules/evas/engines/gl_cocoa/evas_engine.h
@@ -7,7 +7,7 @@
7 7
8#include <OpenGL/gl.h> 8#include <OpenGL/gl.h>
9 9
10#include "evas_gl_common.h" 10#include "../gl_common/evas_gl_common.h"
11#include "Evas_Engine_GL_Cocoa.h" 11#include "Evas_Engine_GL_Cocoa.h"
12#include "../gl_generic/Evas_Engine_GL_Generic.h" 12#include "../gl_generic/Evas_Engine_GL_Generic.h"
13 13
@@ -46,7 +46,12 @@ struct _Render_Engine
46 Render_Engine_GL_Generic generic; 46 Render_Engine_GL_Generic generic;
47 47
48 Outbuf *win; 48 Outbuf *win;
49 int end; 49};
50
51struct _Context_3D
52{
53 Outbuf *ob;
54 void *ns_gl_context;
50}; 55};
51 56
52struct _Outbuf 57struct _Outbuf
@@ -58,36 +63,53 @@ struct _Outbuf
58 void *ns_gl_view; // NSOpenGLView* 63 void *ns_gl_view; // NSOpenGLView*
59 void *ns_window; // NSWindow* 64 void *ns_window; // NSWindow*
60 65
61 int width; 66 int w;
62 int height; 67 int h;
63 68 int rot;
64 // FIXME 69 Render_Engine_Swap_Mode swap_mode;
65 struct {
66 int x1;
67 int y1;
68 int x2;
69 int y2;
70 int redraw : 1;
71 int drew : 1;
72 } draw;
73 70
71 Eina_Bool drew;
74}; 72};
75 73
76 74
77extern Evas_Gl_Symbols glsym_evas_gl_symbols; 75static inline Outbuf *
76eng_get_ob(const Render_Engine *re)
77{
78 return re->generic.software.ob;
79}
80
78extern Evas_GL_Common_Context_New glsym_evas_gl_common_context_new; 81extern Evas_GL_Common_Context_New glsym_evas_gl_common_context_new;
79extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_free; 82extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_free;
80extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_flush; 83extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_flush;
81extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_use; 84extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_use;
85extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_done;
82extern Evas_GL_Common_Context_Resize_Call glsym_evas_gl_common_context_resize; 86extern Evas_GL_Common_Context_Resize_Call glsym_evas_gl_common_context_resize;
87extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_newframe;
88extern Evas_GL_Preload_Render_Call glsym_evas_gl_preload_render_lock;
89extern Evas_GL_Preload_Render_Call glsym_evas_gl_preload_render_unlock;
90extern Evas_Gl_Symbols glsym_evas_gl_symbols;
83 91
84Outbuf *evas_outbuf_new(Evas_Engine_Info_GL_Cocoa *info, int w, int h); 92Outbuf *evas_outbuf_new(Evas_Engine_Info_GL_Cocoa *info, int w, int h);
85void evas_outbuf_free(Outbuf *ob); 93void evas_outbuf_free(Outbuf *ob);
86void evas_outbuf_use(Outbuf *ob); 94void evas_outbuf_use(Outbuf *ob);
87void evas_outbuf_lock_focus(Outbuf *ob); 95int evas_outbuf_rot_get(Outbuf *ob);
88void evas_outbuf_unlock_focus(Outbuf *ob); 96Render_Engine_Swap_Mode evas_outbuf_buffer_state_get(Outbuf *ob);
89void evas_outbuf_resize(Outbuf *ob, int w, int h); 97void evas_outbuf_gl_context_use(Context_3D *ctx);
90void evas_outbuf_swap_buffers(Outbuf *ob); 98Eina_Bool evas_outbuf_update_region_first_rect(Outbuf *ob);
91void evas_outbuf_vsync_set(int on); // FIXME 99void *evas_outbuf_update_region_new(Outbuf *ob, int x, int y, int w, int h, int *cx, int *cy, int *cw, int *ch);
100void evas_outbuf_update_region_push(Outbuf *ob, RGBA_Image *update, int x, int y, int w, int h);
101void evas_outbuf_update_region_free(Outbuf *ob, RGBA_Image *update);
102void evas_outbuf_flush(Outbuf *ob, Tilebuf_Rect *rects, Evas_Render_Mode render_mode);
103Evas_Engine_GL_Context *evas_outbuf_gl_context_get(Outbuf *ob);
104Context_3D *evas_outbuf_gl_context_new(Outbuf *ob);
105void evas_outbuf_gl_context_use(Context_3D *ctx);
106void evas_outbuf_reconfigure(Outbuf *ob, int w, int h, int rot, Outbuf_Depth depth);
107void *evas_outbuf_egl_display_get(Outbuf *ob);
108
109#define GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(...) \
110 do { \
111 CRI("[%s] IS AN IMPLEMENTED CALL. PLEASE REPORT!!", __func__); \
112 return __VA_ARGS__; \
113 } while (0)
92 114
93#endif /* __EVAS_ENGINE_H__ */ 115#endif /* __EVAS_ENGINE_H__ */
diff --git a/src/modules/evas/engines/gl_cocoa/evas_outbuf.m b/src/modules/evas/engines/gl_cocoa/evas_outbuf.m
index 56a1b809b9..3382797844 100644
--- a/src/modules/evas/engines/gl_cocoa/evas_outbuf.m
+++ b/src/modules/evas/engines/gl_cocoa/evas_outbuf.m
@@ -5,7 +5,17 @@
5 5
6#include <dlfcn.h> 6#include <dlfcn.h>
7 7
8#define TRACE
9#undef TRACE // Remove me for intense debug
10
11#ifdef TRACE
12# define TRC(...) DBG(__VA_ARGS__)
13#else
14# define TRC(...)
15#endif
16
8static Outbuf *_evas_gl_cocoa_window = NULL; 17static Outbuf *_evas_gl_cocoa_window = NULL;
18static NSOpenGLContext *_evas_gl_cocoa_shared_context = nil;
9static int _win_count = 0; 19static int _win_count = 0;
10 20
11@interface EvasGLView : NSOpenGLView 21@interface EvasGLView : NSOpenGLView
@@ -18,14 +28,10 @@ static int _win_count = 0;
18 28
19+ (NSOpenGLPixelFormat*) basicPixelFormat 29+ (NSOpenGLPixelFormat*) basicPixelFormat
20{ 30{
21 NSOpenGLPixelFormatAttribute attributes [] = { 31 const NSOpenGLPixelFormatAttribute attributes[] = {
22 NSOpenGLPFAWindow, 32 NSOpenGLPFAAccelerated,
23 NSOpenGLPFAAccelerated, 33 NSOpenGLPFADoubleBuffer,
24 NSOpenGLPFADoubleBuffer, 34 0 /* Terminator */
25 /*NSOpenGLPFAColorSize, 24,
26 NSOpenGLPFAAlphaSize, 8,
27 NSOpenGLPFADepthSize, 24,*/
28 0
29 }; 35 };
30 return [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease]; 36 return [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];
31} 37}
@@ -38,11 +44,26 @@ static int _win_count = 0;
38 pf = [EvasGLView basicPixelFormat]; 44 pf = [EvasGLView basicPixelFormat];
39 self = [super initWithFrame: frameRect 45 self = [super initWithFrame: frameRect
40 pixelFormat: pf]; 46 pixelFormat: pf];
41 ctx = [[NSOpenGLContext alloc] initWithFormat:pf 47
42 shareContext: nil]; 48 /*
49 * Evas GL backend uses a global OpenGL context for all windows inside
50 * an application. Each window has its own texture to render its
51 * content. We use a singleton NSOpenGLContext shared between all
52 * NSOpenGLView, it solves rendering issues for multiple windows.
53 */
54 if (!_evas_gl_cocoa_shared_context)
55 {
56 _evas_gl_cocoa_shared_context = [[NSOpenGLContext alloc] initWithFormat: pf
57 shareContext: nil];
58 ctx = _evas_gl_cocoa_shared_context;
59 }
60 else
61 {
62 ctx = [[NSOpenGLContext alloc] initWithFormat: pf
63 shareContext: _evas_gl_cocoa_shared_context];
64 }
43 65
44 [self setOpenGLContext: ctx]; 66 [self setOpenGLContext: ctx];
45 [ctx setView: self];
46 67
47 return self; 68 return self;
48} 69}
@@ -54,7 +75,9 @@ static int _win_count = 0;
54 75
55- (void)lockFocus 76- (void)lockFocus
56{ 77{
57 NSOpenGLContext* context = [self openGLContext]; 78 NSOpenGLContext *context;
79
80 context = [self openGLContext];
58 81
59 //[super lockFocus]; 82 //[super lockFocus];
60 if ([context view] != self) { 83 if ([context view] != self) {
@@ -65,6 +88,7 @@ static int _win_count = 0;
65 88
66@end 89@end
67 90
91
68static void * 92static void *
69_dlsym(const char *sym) 93_dlsym(const char *sym)
70{ 94{
@@ -79,6 +103,7 @@ evas_outbuf_new(Evas_Engine_Info_GL_Cocoa *info,
79 EINA_SAFETY_ON_NULL_RETURN_VAL(info, NULL); 103 EINA_SAFETY_ON_NULL_RETURN_VAL(info, NULL);
80 104
81 Outbuf *ob; 105 Outbuf *ob;
106 EvasGLView *glview;
82 107
83 ob = calloc(1, sizeof(*ob)); 108 ob = calloc(1, sizeof(*ob));
84 if (EINA_UNLIKELY(!ob)) 109 if (EINA_UNLIKELY(!ob))
@@ -86,22 +111,24 @@ evas_outbuf_new(Evas_Engine_Info_GL_Cocoa *info,
86 CRI("Failed to allocate memory"); 111 CRI("Failed to allocate memory");
87 goto die; 112 goto die;
88 } 113 }
89 _win_count++;
90 114
91 ob->width = w; 115 ob->w = w;
92 ob->height = h; 116 ob->h = h;
93 ob->info = info; 117 ob->info = info;
94 ob->ns_window = info->window; 118 ob->ns_window = info->window;
119 ob->rot = 0;
120 ob->swap_mode = MODE_DOUBLE;
95 121
96 ob->ns_gl_view = [[EvasGLView alloc] initWithFrame: NSMakeRect(0, 0, w, h)]; 122 glview = [[EvasGLView alloc] initWithFrame: NSMakeRect(0, 0, w, h)];
97 if (EINA_UNLIKELY(!ob->ns_gl_view)) 123 if (EINA_UNLIKELY(!glview))
98 { 124 {
99 CRI("Failed to create gl_view"); 125 CRI("Failed to create gl_view");
100 goto die; 126 goto die;
101 } 127 }
102 [[(NSOpenGLView *)ob->ns_gl_view openGLContext] makeCurrentContext]; 128 ob->ns_gl_view = glview;
103 129 [[glview openGLContext] makeCurrentContext];
104 glsym_evas_gl_symbols(_dlsym); 130 glsym_evas_gl_symbols(_dlsym);
131
105 ob->gl_context = glsym_evas_gl_common_context_new(); 132 ob->gl_context = glsym_evas_gl_common_context_new();
106 if (EINA_UNLIKELY(!ob->gl_context)) 133 if (EINA_UNLIKELY(!ob->gl_context))
107 { 134 {
@@ -109,11 +136,11 @@ evas_outbuf_new(Evas_Engine_Info_GL_Cocoa *info,
109 goto die; 136 goto die;
110 } 137 }
111 138
112
113 evas_outbuf_use(ob); 139 evas_outbuf_use(ob);
114 140 glsym_evas_gl_common_context_resize(ob->gl_context,
115 glsym_evas_gl_common_context_resize(ob->gl_context, ob->width, ob->height, 0); // TODO rotation 141 ob->w, ob->h, ob->rot);
116 142 _win_count++;
143 TRC("add: %p", ob);
117 return ob; 144 return ob;
118 145
119die: 146die:
@@ -124,94 +151,186 @@ die:
124void 151void
125evas_outbuf_free(Outbuf *ob) 152evas_outbuf_free(Outbuf *ob)
126{ 153{
127 int refs = 0; 154 TRC("del: %p", ob);
128 155
129 _win_count--;
130 evas_outbuf_use(ob); 156 evas_outbuf_use(ob);
131 157
158 _win_count--;
132 if (_win_count == 0) evas_common_font_ext_clear(); 159 if (_win_count == 0) evas_common_font_ext_clear();
133 160
134 if (ob == _evas_gl_cocoa_window) _evas_gl_cocoa_window = NULL; 161 if (ob == _evas_gl_cocoa_window) _evas_gl_cocoa_window = NULL;
135 if (ob->gl_context) 162 if (ob->gl_context)
136 { 163 {
137 refs = ob->gl_context->references - 1;
138 glsym_evas_gl_common_context_free(ob->gl_context); 164 glsym_evas_gl_common_context_free(ob->gl_context);
139 [(NSOpenGLView *) ob->ns_gl_view release]; 165 [(NSOpenGLView *) ob->ns_gl_view release];
140 } 166 }
141 167
142 if (refs == 0)
143 {
144 // TODO
145 }
146 free(ob); 168 free(ob);
147} 169}
148 170
171static Eina_Bool
172_evas_outbuf_make_current(void *data EINA_UNUSED,
173 void *doit EINA_UNUSED)
174{
175 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(EINA_FALSE);
176}
177
149void 178void
150evas_outbuf_use(Outbuf *ob) 179evas_outbuf_use(Outbuf *ob)
151{ 180{
152 Eina_Bool force = EINA_FALSE; 181 if (_evas_gl_cocoa_window != ob)
153
154 // TODO preload_render_Lock
155
156 if (_evas_gl_cocoa_window)
157 {
158 // TODO ifcurrent context is not glcontext
159 force = EINA_TRUE;
160 }
161
162 if ((_evas_gl_cocoa_window != ob) || (force))
163 { 182 {
164 if (_evas_gl_cocoa_window) 183 if (_evas_gl_cocoa_window)
165 { 184 {
166 glsym_evas_gl_common_context_use(_evas_gl_cocoa_window->gl_context); 185 glsym_evas_gl_common_context_use(_evas_gl_cocoa_window->gl_context);
167 glsym_evas_gl_common_context_flush(_evas_gl_cocoa_window->gl_context); 186 glsym_evas_gl_common_context_flush(_evas_gl_cocoa_window->gl_context);
168 } 187 }
169
170 [[(NSOpenGLView *)ob->ns_gl_view openGLContext] makeCurrentContext];
171 _evas_gl_cocoa_window = ob; 188 _evas_gl_cocoa_window = ob;
172 // TODO blah
173 } 189 }
190 [[(NSOpenGLView* )ob->ns_gl_view openGLContext] makeCurrentContext];
191 glsym_evas_gl_common_context_use(ob->gl_context);
192}
174 193
175 if (ob) glsym_evas_gl_common_context_use(ob->gl_context); 194int
195evas_outbuf_rot_get(Outbuf *ob)
196{
197 return ob->rot;
198}
199
200Render_Engine_Swap_Mode
201evas_outbuf_buffer_state_get(Outbuf *ob)
202{
203 return ob->swap_mode;
204}
205
206Evas_Engine_GL_Context *
207evas_outbuf_gl_context_get(Outbuf *ob)
208{
209 return ob->gl_context;
176} 210}
177 211
178void 212void
179evas_outbuf_resize(Outbuf *ob, 213evas_outbuf_update_region_push(Outbuf *ob,
180 int w, 214 RGBA_Image *update EINA_UNUSED,
181 int h) 215 int x EINA_UNUSED,
216 int y EINA_UNUSED,
217 int w EINA_UNUSED,
218 int h EINA_UNUSED)
219{
220 TRC("");
221 /* Is it really necessary to flush per region ? Shouldn't we be able to
222 still do that for the full canvas when doing partial update */
223 ob->drew = EINA_TRUE;
224 glsym_evas_gl_common_context_flush(ob->gl_context);
225}
226
227void
228evas_outbuf_update_region_free(Outbuf *ob EINA_UNUSED, RGBA_Image *update EINA_UNUSED)
229{
230 TRC("");
231 /* Nothing to do here as we don't really create an image per area */
232}
233
234void *
235evas_outbuf_update_region_new(Outbuf *ob,
236 int x,
237 int y,
238 int w,
239 int h,
240 int *cx EINA_UNUSED,
241 int *cy EINA_UNUSED,
242 int *cw EINA_UNUSED,
243 int *ch EINA_UNUSED)
244{
245 TRC("x,y,w,h = %i,%i,%i,%i", x, y, w, h);
246
247 if ((w == ob->w) && (h == ob->h))
248 ob->gl_context->master_clip.enabled = EINA_FALSE;
249 else
250 {
251 ob->gl_context->master_clip.enabled = EINA_TRUE;
252 ob->gl_context->master_clip.x = x;
253 ob->gl_context->master_clip.y = y;
254 ob->gl_context->master_clip.w = w;
255 ob->gl_context->master_clip.h = h;
256 }
257
258 return ob->gl_context->def_surface;
259}
260
261Eina_Bool
262evas_outbuf_update_region_first_rect(Outbuf *ob)
263{
264 TRC("");
265
266 glsym_evas_gl_preload_render_lock(_evas_outbuf_make_current, ob);
267 evas_outbuf_use(ob);
268
269 glsym_evas_gl_common_context_resize(ob->gl_context,
270 ob->w, ob->h,
271 ob->rot);
272 glsym_evas_gl_common_context_flush(ob->gl_context);
273 glsym_evas_gl_common_context_newframe(ob->gl_context);
274
275 /* To debug partial rendering */
276 //glClearColor(0.2, 0.5, 1.0, 1.0);
277 //glClear(GL_COLOR_BUFFER_BIT);
278
279 return EINA_FALSE;
280}
281
282void
283evas_outbuf_flush(Outbuf *ob,
284 Tilebuf_Rect *rects EINA_UNUSED,
285 Evas_Render_Mode render_mode)
182{ 286{
183 NSRect view_frame;
184 NSOpenGLView *const view = ob->ns_gl_view; 287 NSOpenGLView *const view = ob->ns_gl_view;
185 288
186 INF("Resize %d %d\n", w, h); 289 TRC("drew is %s", ob->drew ? "true" : "false");
290
291 if (render_mode == EVAS_RENDER_MODE_ASYNC_INIT) goto end;
292 if (!ob->drew) goto end;
187 293
188 view_frame = [view frame]; 294 ob->drew = EINA_FALSE;
189 view_frame.size.height = h; 295 evas_outbuf_use(ob);
190 view_frame.size.width = w; 296 glsym_evas_gl_common_context_done(ob->gl_context);
191 297
192 [view setFrame:view_frame];
193 [[view openGLContext] flushBuffer]; 298 [[view openGLContext] flushBuffer];
299end:
300 glsym_evas_gl_preload_render_unlock(_evas_outbuf_make_current, ob);
194} 301}
195 302
196void 303void
197evas_outbuf_lock_focus(Outbuf *ob) 304evas_outbuf_reconfigure(Outbuf *ob,
305 int w,
306 int h,
307 int rot,
308 Outbuf_Depth depth EINA_UNUSED)
198{ 309{
199 [(NSOpenGLView *)ob->ns_gl_view lockFocus]; 310 TRC("w,h = %i,%i", w, h);
311
312 ob->w = w;
313 ob->h = h;
314 ob->rot = rot;
315 evas_outbuf_use(ob);
316 [[(NSOpenGLView *)ob->ns_gl_view openGLContext] flushBuffer];
317 glsym_evas_gl_common_context_resize(ob->gl_context, w, h, rot);
200} 318}
201 319
202void 320void
203evas_outbuf_unlock_focus(Outbuf *ob) 321evas_outbuf_gl_context_use(Context_3D *ctx EINA_UNUSED)
204{ 322{
205 [(NSOpenGLView *)ob->ns_gl_view unlockFocus]; 323 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN();
206} 324}
207 325
208void 326Context_3D *
209evas_outbuf_swap_buffers(Outbuf *ob) 327evas_outbuf_gl_context_new(Outbuf *ob EINA_UNUSED)
210{ 328{
211 [[(NSOpenGLView *)ob->ns_gl_view openGLContext] flushBuffer]; 329 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(NULL);
212} 330}
213 331
214void // FIXME 332void *
215evas_outbuf_vsync_set(int on EINA_UNUSED) 333evas_outbuf_egl_display_get(Outbuf *ob EINA_UNUSED)
216{ 334{
335 GL_COCOA_UNIMPLEMENTED_CALL_SO_RETURN(NULL);
217} 336}