summaryrefslogtreecommitdiff
path: root/legacy/evas/src/modules/engines/gl_sdl/evas_engine.c
diff options
context:
space:
mode:
authorxcomputerman <xcomputerman>2010-01-29 02:31:37 +0000
committerxcomputerman <xcomputerman@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>2010-01-29 02:31:37 +0000
commitcdcc000942064d21c1f685074c3b5ff4453f17dc (patch)
treefa00e05f99b6029ca045ef588d96cff8bb1f79d8 /legacy/evas/src/modules/engines/gl_sdl/evas_engine.c
parenta5a6b927d02503363278f72fecfd671020e2c5df (diff)
Add OpenGL SDL engine
SVN revision: 45674
Diffstat (limited to '')
-rw-r--r--legacy/evas/src/modules/engines/gl_sdl/evas_engine.c1397
1 files changed, 1397 insertions, 0 deletions
diff --git a/legacy/evas/src/modules/engines/gl_sdl/evas_engine.c b/legacy/evas/src/modules/engines/gl_sdl/evas_engine.c
new file mode 100644
index 0000000000..b4e0459ec2
--- /dev/null
+++ b/legacy/evas/src/modules/engines/gl_sdl/evas_engine.c
@@ -0,0 +1,1397 @@
1#include "evas_common.h"
2#include "evas_engine.h"
3
4#include <dlfcn.h> /* dlopen,dlclose,etc */
5
6static void* _sdl_output_setup (int w, int h, int fullscreen, int noframe);
7
8int _evas_engine_GL_SDL_log_dom = -1;
9/* function tables - filled in later (func and parent func) */
10static Evas_Func func, pfunc;
11
12static void *
13eng_info(Evas *e)
14{
15 Evas_Engine_Info_GL_SDL *info;
16
17 info = calloc(1, sizeof(Evas_Engine_Info_GL_SDL));
18 if (!info) return NULL;
19 info->magic.magic = rand();
20 return info;
21}
22
23static void
24eng_info_free(Evas *e __UNUSED__, void *info)
25{
26 Evas_Engine_Info_GL_SDL *in;
27 in = (Evas_Engine_Info_GL_SDL *)info;
28 free(in);
29}
30
31static int
32eng_setup(Evas *e, void *in)
33{
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}
61
62static void
63eng_output_free(void *data)
64{
65 Render_Engine *re;
66
67 re = (Render_Engine *)data;
68 evas_gl_common_context_free(re->gl_context);
69 free(re);
70
71 evas_common_font_shutdown();
72 evas_common_image_shutdown();
73
74 SDL_QuitSubSystem(SDL_INIT_VIDEO);
75}
76
77static void
78eng_output_resize(void *data, int w, int h)
79{
80 Render_Engine *re;
81 SDL_Surface *surface;
82
83 re = (Render_Engine *)data;
84 re->w = w;
85 re->h = h;
86
87 surface = SDL_SetVideoMode(w, h, 32, EVAS_SDL_GL_FLAG
88 | (re->info->flags.fullscreen ? SDL_FULLSCREEN : 0)
89 | (re->info->flags.noframe ? SDL_NOFRAME : 0));
90 if (!surface)
91 {
92 ERR("Unable to change the resolution to : %ix%i", w, h);
93 exit(-1);
94 }
95
96 evas_gl_common_context_resize(re->gl_context, w, h);
97}
98
99static void
100eng_output_tile_size_set(void *data, int w __UNUSED__, int h __UNUSED__)
101{
102// Render_Engine *re;
103//
104// re = (Render_Engine *)data;
105}
106
107static void
108eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
109{
110 Render_Engine *re;
111
112 re = (Render_Engine *)data;
113 evas_gl_common_context_resize(re->gl_context, re->w, re->h);
114 /* smple bounding box */
115 if (!re->draw.redraw)
116 {
117#if 0
118 re->draw.x1 = x;
119 re->draw.y1 = y;
120 re->draw.x2 = x + w - 1;
121 re->draw.y2 = y + h - 1;
122#else
123 re->draw.x1 = 0;
124 re->draw.y1 = 0;
125 re->draw.x2 = re->w - 1;
126 re->draw.y2 = re->h - 1;
127#endif
128 }
129 else
130 {
131 if (x < re->draw.x1) re->draw.x1 = x;
132 if (y < re->draw.y1) re->draw.y1 = y;
133 if ((x + w - 1) > re->draw.x2) re->draw.x2 = x + w - 1;
134 if ((y + h - 1) > re->draw.y2) re->draw.y2 = y + h - 1;
135 }
136 re->draw.redraw = 1;
137}
138
139static void
140eng_output_redraws_rect_del(void *data, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
141{
142// Render_Engine *re;
143//
144// re = (Render_Engine *)data;
145}
146
147static void
148eng_output_redraws_clear(void *data)
149{
150 Render_Engine *re;
151
152 re = (Render_Engine *)data;
153 re->draw.redraw = 0;
154// INF("GL: finish update cycle!");
155}
156
157/* at least the nvidia drivers are so abysmal that copying from the backbuffer
158 * to the front using glCopyPixels() that you literally can WATCH it draw the
159 * pixels slowly across the screen with a window update taking multiple
160 * seconds - so workaround by doing a full buffer render as frankly GL isn't
161 * up to doing anything that isn't done by quake (etc.)
162 */
163#define SLOW_GL_COPY_RECT 1
164/* vsync games - not for now though */
165//#define VSYNC_TO_SCREEN 1
166
167static void *
168eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
169{
170 Render_Engine *re;
171
172 re = (Render_Engine *)data;
173 evas_gl_common_context_flush(re->gl_context);
174 /* get the upate rect surface - return engine data as dummy */
175 if (!re->draw.redraw)
176 {
177// printf("GL: NO updates!\n");
178 return NULL;
179 }
180// printf("GL: update....!\n");
181#ifdef SLOW_GL_COPY_RECT
182 /* if any update - just return the whole canvas - works with swap
183 * buffers then */
184 if (x) *x = 0;
185 if (y) *y = 0;
186 if (w) *w = re->w;
187 if (h) *h = re->h;
188 if (cx) *cx = 0;
189 if (cy) *cy = 0;
190 if (cw) *cw = re->w;
191 if (ch) *ch = re->h;
192#else
193 /* 1 update - INCREDIBLY SLOW if combined with swap_rect in flush. a gl
194 * problem where there just is no hardware path for somethnig that
195 * obviously SHOULD be there */
196 /* only 1 update to minimise gl context games and rendering multiple update
197 * regions as evas does with other engines
198 */
199 if (x) *x = re->draw.x1;
200 if (y) *y = re->draw.y1;
201 if (w) *w = re->draw.x2 - re->draw.x1 + 1;
202 if (h) *h = re->draw.y2 - re->draw.y1 + 1;
203 if (cx) *cx = re->draw.x1;
204 if (cy) *cy = re->draw.y1;
205 if (cw) *cw = re->draw.x2 - re->draw.x1 + 1;
206 if (ch) *ch = re->draw.y2 - re->draw.y1 + 1;
207#endif
208// clear buffer. only needed for dest alpha
209// glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
210// glClear(GL_COLOR_BUFFER_BIT);
211//x// printf("frame -> new\n");
212 return re->gl_context->def_surface;
213}
214
215static void
216eng_output_redraws_next_update_push(void *data, void *surface __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
217{
218 Render_Engine *re;
219
220 re = (Render_Engine *)data;
221 /* put back update surface.. in this case just unflag redraw */
222 re->draw.redraw = 0;
223 re->draw.drew = 1;
224 evas_gl_common_context_flush(re->gl_context);
225//x// printf("frame -> push\n");
226}
227
228static void
229eng_output_flush(void *data)
230{
231 Render_Engine *re;
232
233 re = (Render_Engine *)data;
234 if (!re->draw.drew) return;
235//x// printf("frame -> flush\n");
236 re->draw.drew = 0;
237
238#if 0
239#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
240// glFlush();
241 eglSwapBuffers(re->egl_disp, re->egl_surface[0]);
242#else
243 glXSwapBuffers(re->win->disp, re->win);
244#endif
245#else
246 SDL_GL_SwapBuffers();
247#endif
248}
249
250static void
251eng_output_idle_flush(void *data)
252{
253// Render_Engine *re;
254//
255// re = (Render_Engine *)data;
256}
257
258static void
259eng_context_cutout_add(void *data, void *context, int x, int y, int w, int h)
260{
261// Render_Engine *re;
262//
263// re = (Render_Engine *)data;
264// re->gl_context->dc = context;
265 evas_common_draw_context_add_cutout(context, x, y, w, h);
266}
267
268static void
269eng_context_cutout_clear(void *data, void *context)
270{
271// Render_Engine *re;
272//
273// re = (Render_Engine *)data;
274// re->gl_context->dc = context;
275 evas_common_draw_context_clear_cutouts(context);
276}
277
278static void
279eng_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h)
280{
281 Render_Engine *re;
282
283 re = (Render_Engine *)data;
284 evas_gl_common_context_target_surface_set(re->gl_context, surface);
285 re->gl_context->dc = context;
286 evas_gl_common_rect_draw(re->gl_context, x, y, w, h);
287}
288
289static void
290eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2)
291{
292 Render_Engine *re;
293
294 re = (Render_Engine *)data;
295 evas_gl_common_context_target_surface_set(re->gl_context, surface);
296 re->gl_context->dc = context;
297 evas_gl_common_line_draw(re->gl_context, x1, y1, x2, y2);
298}
299
300static void *
301eng_polygon_point_add(void *data, void *context __UNUSED__, void *polygon, int x, int y)
302{
303 Render_Engine *re;
304
305 re = (Render_Engine *)data;
306 return evas_gl_common_poly_point_add(polygon, x, y);
307}
308
309static void *
310eng_polygon_points_clear(void *data, void *context __UNUSED__, void *polygon)
311{
312 Render_Engine *re;
313
314 re = (Render_Engine *)data;
315 return evas_gl_common_poly_points_clear(polygon);
316}
317
318static void
319eng_polygon_draw(void *data, void *context, void *surface, void *polygon)
320{
321 Render_Engine *re;
322
323 re = (Render_Engine *)data;
324 evas_gl_common_context_target_surface_set(re->gl_context, surface);
325 re->gl_context->dc = context;
326 evas_gl_common_poly_draw(re->gl_context, polygon);
327}
328
329static void
330eng_gradient2_color_np_stop_insert(void *data __UNUSED__, void *gradient __UNUSED__, int r __UNUSED__, int g __UNUSED__, int b __UNUSED__, int a __UNUSED__, float pos __UNUSED__)
331{
332 evas_common_gradient2_color_np_stop_insert(gradient, r, g, b, a, pos);
333}
334
335static void
336eng_gradient2_clear(void *data __UNUSED__, void *gradient __UNUSED__)
337{
338 evas_common_gradient2_clear(gradient);
339}
340
341static void
342eng_gradient2_fill_transform_set(void *data __UNUSED__, void *gradient __UNUSED__, void *transform __UNUSED__)
343{
344 evas_common_gradient2_fill_transform_set(gradient, transform);
345}
346
347static void
348eng_gradient2_fill_spread_set(void *data __UNUSED__, void *gradient __UNUSED__, int spread __UNUSED__)
349{
350 evas_common_gradient2_fill_spread_set(gradient, spread);
351}
352
353static void *
354eng_gradient2_linear_new(void *data __UNUSED__)
355{
356 return evas_common_gradient2_linear_new();
357}
358
359static void
360eng_gradient2_linear_free(void *data __UNUSED__, void *linear_gradient __UNUSED__)
361{
362 evas_common_gradient2_free(linear_gradient);
363}
364
365static void
366eng_gradient2_linear_fill_set(void *data __UNUSED__, void *linear_gradient __UNUSED__, float x0 __UNUSED__, float y0 __UNUSED__, float x1 __UNUSED__, float y1 __UNUSED__)
367{
368 evas_common_gradient2_linear_fill_set(linear_gradient, x0, y0, x1, y1);
369}
370
371static int
372eng_gradient2_linear_is_opaque(void *data __UNUSED__, void *context __UNUSED__, void *linear_gradient __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
373{
374 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
375 RGBA_Gradient2 *gr = (RGBA_Gradient2 *)linear_gradient;
376
377 if (!dc || !gr || !gr->type.geometer) return 0;
378 return !(gr->type.geometer->has_alpha(gr, dc->render_op) |
379 gr->type.geometer->has_mask(gr, dc->render_op));
380}
381
382static int
383eng_gradient2_linear_is_visible(void *data __UNUSED__, void *context __UNUSED__, void *linear_gradient __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
384{
385 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
386
387 if (!dc || !linear_gradient) return 0;
388 return 1;
389}
390
391static void
392eng_gradient2_linear_render_pre(void *data __UNUSED__, void *context __UNUSED__, void *linear_gradient __UNUSED__)
393{
394 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
395 RGBA_Gradient2 *gr = (RGBA_Gradient2 *)linear_gradient;
396 int len;
397
398 if (!dc || !gr || !gr->type.geometer) return;
399 gr->type.geometer->geom_update(gr);
400 len = gr->type.geometer->get_map_len(gr);
401 evas_common_gradient2_map(dc, gr, len);
402}
403
404static void
405eng_gradient2_linear_render_post(void *data __UNUSED__, void *linear_gradient __UNUSED__)
406{
407}
408
409static void
410eng_gradient2_linear_draw(void *data __UNUSED__, void *context __UNUSED__, void *surface __UNUSED__, void *linear_gradient __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
411{
412 Render_Engine *re;
413
414 re = (Render_Engine *)data;
415 re->gl_context->dc = context;
416 {
417 Evas_GL_Image *gim;
418 RGBA_Image *im;
419 RGBA_Draw_Context *dc = context;
420 int op = dc->render_op, cuse = dc->clip.use;
421
422 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
423 im = (RGBA_Image *)evas_cache_image_size_set(&im->cache_entry, w, h);
424
425 dc->render_op = _EVAS_RENDER_FILL;
426 dc->clip.use = 0;
427
428 // draw to buf, copy to tex, draw tex
429 evas_common_gradient2_draw(im, dc, 0, 0, w, h, linear_gradient);
430
431 gim = evas_gl_common_image_new_from_data(re->gl_context, w, h,
432 im->image.data, 1,
433 EVAS_COLORSPACE_ARGB8888);
434 dc->render_op = op;
435 dc->clip.use = cuse;
436 evas_gl_common_image_draw(re->gl_context, gim, 0, 0, w, h, x, y, w, h, 0);
437 evas_cache_image_drop(&im->cache_entry);
438 evas_gl_common_image_free(gim);
439 }
440}
441
442static void *
443eng_gradient2_radial_new(void *data __UNUSED__)
444{
445 return evas_common_gradient2_radial_new();
446}
447
448static void
449eng_gradient2_radial_free(void *data __UNUSED__, void *radial_gradient __UNUSED__)
450{
451 evas_common_gradient2_free(radial_gradient);
452}
453
454static void
455eng_gradient2_radial_fill_set(void *data __UNUSED__, void *radial_gradient __UNUSED__, float cx __UNUSED__, float cy __UNUSED__, float rx __UNUSED__, float ry __UNUSED__)
456{
457 evas_common_gradient2_radial_fill_set(radial_gradient, cx, cy, rx, ry);
458}
459
460static int
461eng_gradient2_radial_is_opaque(void *data __UNUSED__, void *context __UNUSED__, void *radial_gradient __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
462{
463 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
464 RGBA_Gradient2 *gr = (RGBA_Gradient2 *)radial_gradient;
465
466 if (!dc || !gr || !gr->type.geometer) return 0;
467 return !(gr->type.geometer->has_alpha(gr, dc->render_op) |
468 gr->type.geometer->has_mask(gr, dc->render_op));
469}
470
471static int
472eng_gradient2_radial_is_visible(void *data __UNUSED__, void *context __UNUSED__, void *radial_gradient __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
473{
474 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
475
476 if (!dc || !radial_gradient) return 0;
477 return 1;
478}
479
480static void
481eng_gradient2_radial_render_pre(void *data __UNUSED__, void *context __UNUSED__, void *radial_gradient __UNUSED__)
482{
483 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
484 RGBA_Gradient2 *gr = (RGBA_Gradient2 *)radial_gradient;
485 int len;
486
487 if (!dc || !gr || !gr->type.geometer) return;
488 gr->type.geometer->geom_update(gr);
489 len = gr->type.geometer->get_map_len(gr);
490 evas_common_gradient2_map(dc, gr, len);
491}
492
493static void
494eng_gradient2_radial_render_post(void *data __UNUSED__, void *radial_gradient __UNUSED__)
495{
496}
497
498static void
499eng_gradient2_radial_draw(void *data __UNUSED__, void *context __UNUSED__, void *surface __UNUSED__, void *radial_gradient __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
500{
501 Render_Engine *re;
502
503 re = (Render_Engine *)data;
504 re->gl_context->dc = context;
505 {
506 Evas_GL_Image *gim;
507 RGBA_Image *im;
508 RGBA_Draw_Context *dc = context;
509 int op = dc->render_op, cuse = dc->clip.use;
510
511 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
512 im = (RGBA_Image *)evas_cache_image_size_set(&im->cache_entry, w, h);
513
514 dc->render_op = _EVAS_RENDER_FILL;
515 dc->clip.use = 0;
516
517 // draw to buf, copy to tex, draw tex
518 evas_common_gradient2_draw(im, dc, 0, 0, w, h, radial_gradient);
519
520 gim = evas_gl_common_image_new_from_data(re->gl_context, w, h,
521 im->image.data, 1,
522 EVAS_COLORSPACE_ARGB8888);
523 dc->render_op = op;
524 dc->clip.use = cuse;
525 evas_gl_common_image_draw(re->gl_context, gim, 0, 0, w, h, x, y, w, h, 0);
526 evas_cache_image_drop(&im->cache_entry);
527 evas_gl_common_image_free(gim);
528 }
529}
530
531static void *
532eng_gradient_new(void *data __UNUSED__)
533{
534 return evas_common_gradient_new();
535}
536
537static void
538eng_gradient_free(void *data __UNUSED__, void *gradient)
539{
540 evas_common_gradient_free(gradient);
541}
542
543static void
544eng_gradient_color_stop_add(void *data __UNUSED__, void *gradient, int r, int g, int b, int a, int delta)
545{
546 evas_common_gradient_color_stop_add(gradient, r, g, b, a, delta);
547}
548
549static void
550eng_gradient_alpha_stop_add(void *data __UNUSED__, void *gradient, int a, int delta)
551{
552 evas_common_gradient_alpha_stop_add(gradient, a, delta);
553}
554
555static void
556eng_gradient_color_data_set(void *data __UNUSED__, void *gradient, void *map, int len, int has_alpha)
557{
558 evas_common_gradient_color_data_set(gradient, map, len, has_alpha);
559}
560
561static void
562eng_gradient_alpha_data_set(void *data __UNUSED__, void *gradient, void *alpha_map, int len)
563{
564 evas_common_gradient_alpha_data_set(gradient, alpha_map, len);
565}
566
567static void
568eng_gradient_clear(void *data __UNUSED__, void *gradient)
569{
570 evas_common_gradient_clear(gradient);
571}
572
573static void
574eng_gradient_fill_set(void *data __UNUSED__, void *gradient, int x, int y, int w, int h)
575{
576 evas_common_gradient_fill_set(gradient, x, y, w, h);
577}
578
579static void
580eng_gradient_fill_angle_set(void *data __UNUSED__, void *gradient, double angle)
581{
582 evas_common_gradient_fill_angle_set(gradient, angle);
583}
584
585static void
586eng_gradient_fill_spread_set(void *data __UNUSED__, void *gradient, int spread)
587{
588 evas_common_gradient_fill_spread_set(gradient, spread);
589}
590
591static void
592eng_gradient_angle_set(void *data __UNUSED__, void *gradient, double angle)
593{
594 evas_common_gradient_map_angle_set(gradient, angle);
595}
596
597static void
598eng_gradient_offset_set(void *data __UNUSED__, void *gradient, float offset)
599{
600 evas_common_gradient_map_offset_set(gradient, offset);
601}
602
603static void
604eng_gradient_direction_set(void *data __UNUSED__, void *gradient, int direction)
605{
606 evas_common_gradient_map_direction_set(gradient, direction);
607}
608
609static void
610eng_gradient_type_set(void *data __UNUSED__, void *gradient, char *name, char *params)
611{
612 evas_common_gradient_type_set(gradient, name, params);
613}
614
615static int
616eng_gradient_is_opaque(void *data, void *context, void *gradient, int x, int y, int w, int h)
617{
618 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
619 RGBA_Gradient *gr = (RGBA_Gradient *)gradient;
620
621 if (!dc || !gr || !gr->type.geometer) return 0;
622 return !(gr->type.geometer->has_alpha(gr, dc->render_op) |
623 gr->type.geometer->has_mask(gr, dc->render_op));
624}
625
626static int
627eng_gradient_is_visible(void *data, void *context, void *gradient, int x, int y, int w, int h)
628{
629 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
630
631 if (!dc || !gradient) return 0;
632 return 1;
633}
634
635static void
636eng_gradient_render_pre(void *data, void *context, void *gradient)
637{
638 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
639 RGBA_Gradient *gr = (RGBA_Gradient *)gradient;
640 int len;
641
642 if (!dc || !gr || !gr->type.geometer) return;
643 gr->type.geometer->geom_set(gr);
644 len = gr->type.geometer->get_map_len(gr);
645 evas_common_gradient_map(dc, gr, len);
646}
647
648static void
649eng_gradient_render_post(void *data __UNUSED__, void *gradient)
650{
651}
652
653static void
654eng_gradient_draw(void *data, void *context, void *surface __UNUSED__, void *gradient, int x, int y, int w, int h)
655{
656 Render_Engine *re;
657
658 re = (Render_Engine *)data;
659 re->gl_context->dc = context;
660 {
661 Evas_GL_Image *gim;
662 RGBA_Image *im;
663 RGBA_Draw_Context *dc = context;
664 int op = dc->render_op, cuse = dc->clip.use;
665
666 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
667 im = (RGBA_Image *)evas_cache_image_size_set(&im->cache_entry, w, h);
668
669 dc->render_op = _EVAS_RENDER_FILL;
670 dc->clip.use = 0;
671
672 // draw to buf, copy to tex, draw tex
673 evas_common_gradient_draw(im, dc, 0, 0, w, h, gradient);
674
675 gim = evas_gl_common_image_new_from_data(re->gl_context, w, h,
676 im->image.data, 1,
677 EVAS_COLORSPACE_ARGB8888);
678 dc->render_op = op;
679 dc->clip.use = cuse;
680 evas_gl_common_image_draw(re->gl_context, gim, 0, 0, w, h, x, y, w, h, 0);
681 evas_cache_image_drop(&im->cache_entry);
682 evas_gl_common_image_free(gim);
683 }
684}
685
686static int
687eng_image_alpha_get(void *data, void *image)
688{
689// Render_Engine *re;
690 Evas_GL_Image *im;
691
692// re = (Render_Engine *)data;
693 if (!image) return 1;
694 im = image;
695 return im->alpha;
696}
697
698static int
699eng_image_colorspace_get(void *data, void *image)
700{
701// Render_Engine *re;
702 Evas_GL_Image *im;
703
704// re = (Render_Engine *)data;
705 if (!image) return EVAS_COLORSPACE_ARGB8888;
706 im = image;
707 return im->cs.space;
708}
709
710static void *
711eng_image_alpha_set(void *data, void *image, int has_alpha)
712{
713 Render_Engine *re;
714 Evas_GL_Image *im;
715
716 re = (Render_Engine *)data;
717 if (!image) return NULL;
718 im = image;
719 if (im->native.data)
720 {
721 im->alpha = has_alpha;
722 return image;
723 }
724 /* FIXME: can move to gl_common */
725 if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im;
726 if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image;
727 else if ((!has_alpha) && (!im->im->cache_entry.flags.alpha)) return image;
728 if (im->references > 1)
729 {
730 Evas_GL_Image *im_new;
731
732 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,
733 eng_image_alpha_get(data, image),
734 eng_image_colorspace_get(data, image));
735 if (!im_new) return im;
736 evas_gl_common_image_free(im);
737 im = im_new;
738 }
739 else
740 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
741 im->im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
742 return image;
743}
744
745static void *
746eng_image_border_set(void *data, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
747{
748// Render_Engine *re;
749//
750// re = (Render_Engine *)data;
751 return image;
752}
753
754static void
755eng_image_border_get(void *data, void *image __UNUSED__, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
756{
757// Render_Engine *re;
758//
759// re = (Render_Engine *)data;
760}
761
762static char *
763eng_image_comment_get(void *data, void *image, char *key __UNUSED__)
764{
765// Render_Engine *re;
766 Evas_GL_Image *im;
767
768// re = (Render_Engine *)data;
769 if (!image) return NULL;
770 im = image;
771 if (!im->im) return NULL;
772 return im->im->info.comment;
773}
774
775static char *
776eng_image_format_get(void *data, void *image)
777{
778// Render_Engine *re;
779 Evas_GL_Image *im;
780
781// re = (Render_Engine *)data;
782 im = image;
783 return NULL;
784}
785
786static void
787eng_image_colorspace_set(void *data, void *image, int cspace)
788{
789 Render_Engine *re;
790 Evas_GL_Image *im;
791
792 re = (Render_Engine *)data;
793 if (!image) return;
794 im = image;
795 if (im->native.data) return;
796 /* FIXME: can move to gl_common */
797 if (im->cs.space == cspace) return;
798 evas_cache_image_colorspace(&im->im->cache_entry, cspace);
799 switch (cspace)
800 {
801 case EVAS_COLORSPACE_ARGB8888:
802 if (im->cs.data)
803 {
804 if (!im->cs.no_free) free(im->cs.data);
805 im->cs.data = NULL;
806 im->cs.no_free = 0;
807 }
808 break;
809 case EVAS_COLORSPACE_YCBCR422P601_PL:
810 case EVAS_COLORSPACE_YCBCR422P709_PL:
811 if (im->tex) evas_gl_common_texture_free(im->tex);
812 im->tex = NULL;
813 if (im->cs.data)
814 {
815 if (!im->cs.no_free) free(im->cs.data);
816 }
817 im->cs.data = calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
818 im->cs.no_free = 0;
819 break;
820 default:
821 abort();
822 break;
823 }
824 im->cs.space = cspace;
825}
826
827/////////////////////////////////////////////////////////////////////////
828//
829//
830typedef struct _Native Native;
831
832struct _Native
833{
834 Evas_Native_Surface ns;
835
836#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
837 EGLSurface egl_surface;
838#endif
839};
840
841static void
842_native_bind_cb(void *data, void *image)
843{
844}
845
846static void
847_native_unbind_cb(void *data, void *image)
848{
849}
850
851static void
852_native_free_cb(void *data, void *image)
853{
854}
855
856static void
857eng_image_native_set(void *data, void *image, void *native)
858{
859}
860
861static void *
862eng_image_native_get(void *data, void *image)
863{
864 return NULL;
865}
866
867//
868//
869/////////////////////////////////////////////////////////////////////////
870
871static void *
872eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
873{
874 Render_Engine *re;
875
876 re = (Render_Engine *)data;
877 *error = EVAS_LOAD_ERROR_NONE;
878 return evas_gl_common_image_load(re->gl_context, file, key, lo, error);
879}
880
881static void *
882eng_image_new_from_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
883{
884 Render_Engine *re;
885
886 re = (Render_Engine *)data;
887 return evas_gl_common_image_new_from_data(re->gl_context, w, h, image_data, alpha, cspace);
888}
889
890static void *
891eng_image_new_from_copied_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
892{
893 Render_Engine *re;
894
895 re = (Render_Engine *)data;
896 return evas_gl_common_image_new_from_copied_data(re->gl_context, w, h, image_data, alpha, cspace);
897}
898
899static void
900eng_image_free(void *data, void *image)
901{
902 Render_Engine *re;
903
904 re = (Render_Engine *)data;
905 if (!image) return;
906 evas_gl_common_image_free(image);
907}
908
909static void
910eng_image_size_get(void *data, void *image, int *w, int *h)
911{
912// Render_Engine *re;
913//
914// re = (Render_Engine *)data;
915 if (!image)
916 {
917 *w = 0;
918 *h = 0;
919 return;
920 }
921 if (w) *w = ((Evas_GL_Image *)image)->w;
922 if (h) *h = ((Evas_GL_Image *)image)->h;
923}
924
925static void *
926eng_image_size_set(void *data, void *image, int w, int h)
927{
928 Render_Engine *re;
929 Evas_GL_Image *im = image;
930 Evas_GL_Image *im_old;
931
932 re = (Render_Engine *)data;
933 if (!im) return NULL;
934 if (im->native.data)
935 {
936 im->w = w;
937 im->h = h;
938 return image;
939 }
940 im_old = image;
941 if ((eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P601_PL) ||
942 (eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P709_PL))
943 w &= ~0x1;
944 if ((im_old) && (im_old->im->cache_entry.w == w) && (im_old->im->cache_entry.h == h))
945 return image;
946 if (im_old)
947 {
948 im = evas_gl_common_image_new(re->gl_context, w, h,
949 eng_image_alpha_get(data, image),
950 eng_image_colorspace_get(data, image));
951/*
952 evas_common_load_image_data_from_file(im_old->im);
953 if (im_old->im->image->data)
954 {
955 evas_common_blit_rectangle(im_old->im, im->im, 0, 0, w, h, 0, 0);
956 evas_common_cpu_end_opt();
957 }
958 */
959 evas_gl_common_image_free(im_old);
960 }
961 else
962 im = evas_gl_common_image_new(re->gl_context, w, h, 1, EVAS_COLORSPACE_ARGB8888);
963 return im;
964}
965
966static void *
967eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
968{
969 Render_Engine *re;
970 Evas_GL_Image *im = image;
971
972 re = (Render_Engine *)data;
973 if (!image) return NULL;
974 if (im->native.data) return image;
975 evas_gl_common_image_dirty(image, x, y, w, h);
976 return image;
977}
978
979static void *
980eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data)
981{
982 Render_Engine *re;
983 Evas_GL_Image *im;
984
985 re = (Render_Engine *)data;
986 if (!image)
987 {
988 *image_data = NULL;
989 return NULL;
990 }
991 im = image;
992 if (im->native.data)
993 {
994 *image_data = NULL;
995 return im;
996 }
997 evas_cache_image_load_data(&im->im->cache_entry);
998 switch (im->cs.space)
999 {
1000 case EVAS_COLORSPACE_ARGB8888:
1001 if (to_write)
1002 {
1003 if (im->references > 1)
1004 {
1005 Evas_GL_Image *im_new;
1006
1007 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,
1008 eng_image_alpha_get(data, image),
1009 eng_image_colorspace_get(data, image));
1010 if (!im_new)
1011 {
1012 *image_data = NULL;
1013 return im;
1014 }
1015 evas_gl_common_image_free(im);
1016 im = im_new;
1017 }
1018 else
1019 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
1020 }
1021 *image_data = im->im->image.data;
1022 break;
1023 case EVAS_COLORSPACE_YCBCR422P601_PL:
1024 case EVAS_COLORSPACE_YCBCR422P709_PL:
1025 *image_data = im->cs.data;
1026 break;
1027 default:
1028 abort();
1029 break;
1030 }
1031 return im;
1032}
1033
1034static void *
1035eng_image_data_put(void *data, void *image, DATA32 *image_data)
1036{
1037 Render_Engine *re;
1038 Evas_GL_Image *im, *im2;
1039
1040 re = (Render_Engine *)data;
1041 if (!image) return NULL;
1042 im = image;
1043 if (im->native.data) return image;
1044 switch (im->cs.space)
1045 {
1046 case EVAS_COLORSPACE_ARGB8888:
1047 if (image_data != im->im->image.data)
1048 {
1049 int w, h;
1050
1051 w = im->im->cache_entry.w;
1052 h = im->im->cache_entry.h;
1053 im2 = eng_image_new_from_data(data, w, h, image_data,
1054 eng_image_alpha_get(data, image),
1055 eng_image_colorspace_get(data, image));
1056 if (!im2) return im;
1057 evas_gl_common_image_free(im);
1058 im = im2;
1059 }
1060 break;
1061 case EVAS_COLORSPACE_YCBCR422P601_PL:
1062 case EVAS_COLORSPACE_YCBCR422P709_PL:
1063 if (image_data != im->cs.data)
1064 {
1065 if (im->cs.data)
1066 {
1067 if (!im->cs.no_free) free(im->cs.data);
1068 }
1069 im->cs.data = image_data;
1070 }
1071 break;
1072 default:
1073 abort();
1074 break;
1075 }
1076 /* hmmm - but if we wrote... why bother? */
1077 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
1078 return im;
1079}
1080
1081static void
1082eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
1083{
1084 Evas_GL_Image *gim = image;
1085 RGBA_Image *im;
1086
1087 if (!gim) return;
1088 if (gim->native.data) return;
1089 im = (RGBA_Image *)gim->im;
1090 if (!im) return;
1091 evas_cache_image_preload_data(&im->cache_entry, target);
1092}
1093
1094static void
1095eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
1096{
1097 Evas_GL_Image *gim = image;
1098 RGBA_Image *im;
1099
1100 if (!gim) return;
1101 if (gim->native.data) return;
1102 im = (RGBA_Image *)gim->im;
1103 if (!im) return;
1104 evas_cache_image_preload_cancel(&im->cache_entry, target);
1105}
1106
1107static void
1108eng_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)
1109{
1110 Render_Engine *re;
1111
1112 re = (Render_Engine *)data;
1113 if (!image) return;
1114 evas_gl_common_context_target_surface_set(re->gl_context, surface);
1115 re->gl_context->dc = context;
1116 evas_gl_common_image_draw(re->gl_context, image,
1117 src_x, src_y, src_w, src_h,
1118 dst_x, dst_y, dst_w, dst_h,
1119 smooth);
1120}
1121
1122static void
1123eng_image_scale_hint_set(void *data __UNUSED__, void *image, int hint)
1124{
1125}
1126
1127static void
1128eng_image_map4_draw(void *data __UNUSED__, void *context, void *surface, void *image, RGBA_Map_Point *p, int smooth, int level)
1129{
1130 Render_Engine *re;
1131
1132 re = (Render_Engine *)data;
1133 evas_gl_common_context_target_surface_set(re->gl_context, surface);
1134 re->gl_context->dc = context;
1135 evas_gl_common_image_map4_draw(re->gl_context, image, p, smooth, level);
1136}
1137
1138static void *
1139eng_image_map_surface_new(void *data __UNUSED__, int w, int h, int alpha)
1140{
1141 Render_Engine *re;
1142
1143 re = (Render_Engine *)data;
1144 return evas_gl_common_image_surface_new(re->gl_context, w, h, alpha);
1145}
1146
1147static void
1148eng_image_map_surface_free(void *data __UNUSED__, void *surface)
1149{
1150 evas_gl_common_image_free(surface);
1151}
1152
1153static int
1154eng_image_scale_hint_get(void *data __UNUSED__, void *image)
1155{
1156 return EVAS_IMAGE_SCALE_HINT_NONE;
1157}
1158
1159static void
1160eng_font_draw(void *data, void *context, void *surface, void *font, int x, int y, int w __UNUSED__, int h __UNUSED__, int ow __UNUSED__, int oh __UNUSED__, const char *text)
1161{
1162 Render_Engine *re;
1163
1164 re = (Render_Engine *)data;
1165 evas_gl_common_context_target_surface_set(re->gl_context, surface);
1166 re->gl_context->dc = context;
1167 {
1168 // FIXME: put im into context so we can free it
1169 static RGBA_Image *im = NULL;
1170
1171 if (!im)
1172 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
1173 im->cache_entry.w = re->w;
1174 im->cache_entry.h = re->h;
1175 evas_common_draw_context_font_ext_set(context,
1176 re->gl_context,
1177 evas_gl_font_texture_new,
1178 evas_gl_font_texture_free,
1179 evas_gl_font_texture_draw);
1180 evas_common_font_draw(im, context, font, x, y, text);
1181 evas_common_draw_context_font_ext_set(context,
1182 NULL,
1183 NULL,
1184 NULL,
1185 NULL);
1186 }
1187}
1188
1189static Eina_Bool
1190eng_canvas_alpha_get(void *data __UNUSED__, void *info __UNUSED__)
1191{
1192 // FIXME: support ARGB gl targets!!!
1193 return EINA_FALSE;
1194}
1195
1196static int
1197module_open(Evas_Module *em)
1198{
1199 if (!em) return 0;
1200 /* get whatever engine module we inherit from */
1201 if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
1202 if (_evas_engine_GL_SDL_log_dom < 0)
1203 _evas_engine_GL_SDL_log_dom = eina_log_domain_register("EvasEngineGLSDL", EVAS_DEFAULT_LOG_COLOR);
1204 if (_evas_engine_GL_SDL_log_dom < 0)
1205 {
1206 EINA_LOG_ERR("Impossible to create a log domain for GL SDL engine.\n");
1207 return 0;
1208 }
1209 /* store it for later use */
1210 func = pfunc;
1211 /* now to override methods */
1212 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
1213 ORD(info);
1214 ORD(info_free);
1215 ORD(setup);
1216 ORD(canvas_alpha_get);
1217 ORD(output_free);
1218 ORD(output_resize);
1219 ORD(output_tile_size_set);
1220 ORD(output_redraws_rect_add);
1221 ORD(output_redraws_rect_del);
1222 ORD(output_redraws_clear);
1223 ORD(output_redraws_next_update_get);
1224 ORD(output_redraws_next_update_push);
1225 ORD(context_cutout_add);
1226 ORD(context_cutout_clear);
1227 ORD(output_flush);
1228 ORD(output_idle_flush);
1229 ORD(rectangle_draw);
1230 ORD(line_draw);
1231 ORD(polygon_point_add);
1232 ORD(polygon_points_clear);
1233 ORD(polygon_draw);
1234
1235 ORD(gradient2_color_np_stop_insert);
1236 ORD(gradient2_clear);
1237 ORD(gradient2_fill_transform_set);
1238 ORD(gradient2_fill_spread_set);
1239 ORD(gradient2_linear_new);
1240 ORD(gradient2_linear_free);
1241 ORD(gradient2_linear_fill_set);
1242 ORD(gradient2_linear_is_opaque);
1243 ORD(gradient2_linear_is_visible);
1244 ORD(gradient2_linear_render_pre);
1245 ORD(gradient2_linear_render_post);
1246 ORD(gradient2_linear_draw);
1247 ORD(gradient2_radial_new);
1248 ORD(gradient2_radial_free);
1249 ORD(gradient2_radial_fill_set);
1250 ORD(gradient2_radial_is_opaque);
1251 ORD(gradient2_radial_is_visible);
1252 ORD(gradient2_radial_render_pre);
1253 ORD(gradient2_radial_render_post);
1254 ORD(gradient2_radial_draw);
1255
1256 ORD(gradient_new);
1257 ORD(gradient_free);
1258 ORD(gradient_color_stop_add);
1259 ORD(gradient_alpha_stop_add);
1260 ORD(gradient_color_data_set);
1261 ORD(gradient_alpha_data_set);
1262 ORD(gradient_clear);
1263 ORD(gradient_fill_set);
1264 ORD(gradient_fill_angle_set);
1265 ORD(gradient_fill_spread_set);
1266 ORD(gradient_angle_set);
1267 ORD(gradient_offset_set);
1268 ORD(gradient_direction_set);
1269 ORD(gradient_type_set);
1270 ORD(gradient_is_opaque);
1271 ORD(gradient_is_visible);
1272 ORD(gradient_render_pre);
1273 ORD(gradient_render_post);
1274 ORD(gradient_draw);
1275 ORD(image_load);
1276 ORD(image_new_from_data);
1277 ORD(image_new_from_copied_data);
1278 ORD(image_free);
1279 ORD(image_size_get);
1280 ORD(image_size_set);
1281 ORD(image_dirty_region);
1282 ORD(image_data_get);
1283 ORD(image_data_put);
1284 ORD(image_data_preload_request);
1285 ORD(image_data_preload_cancel);
1286 ORD(image_alpha_set);
1287 ORD(image_alpha_get);
1288 ORD(image_border_set);
1289 ORD(image_border_get);
1290 ORD(image_draw);
1291 ORD(image_comment_get);
1292 ORD(image_format_get);
1293 ORD(image_colorspace_set);
1294 ORD(image_colorspace_get);
1295 ORD(image_native_set);
1296 ORD(image_native_get);
1297 ORD(font_draw);
1298
1299 ORD(image_scale_hint_set);
1300 ORD(image_scale_hint_get);
1301
1302 ORD(image_map4_draw);
1303 ORD(image_map_surface_new);
1304 ORD(image_map_surface_free);
1305
1306 /* now advertise out own api */
1307 em->functions = (void *)(&func);
1308 return 1;
1309}
1310
1311static void
1312module_close(Evas_Module *em)
1313{
1314 eina_log_domain_unregister(_evas_engine_GL_SDL_log_dom);
1315}
1316
1317static Evas_Module_Api evas_modapi =
1318{
1319 EVAS_MODULE_API_VERSION,
1320 "gl_sdl",
1321 "none",
1322 {
1323 module_open,
1324 module_close
1325 }
1326};
1327
1328EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, gl_sdl);
1329
1330#ifndef EVAS_STATIC_BUILD_GL_SDL
1331EVAS_EINA_MODULE_DEFINE(engine, gl_sdl);
1332#endif
1333
1334static void*
1335_sdl_output_setup (int w, int h, int fullscreen, int noframe)
1336{
1337 Render_Engine *re = calloc(1, sizeof(Render_Engine));
1338 SDL_Surface *surface;
1339 int context_attrs[3];
1340 int config_attrs[20];
1341 int major_version, minor_version;
1342 int num_config;
1343
1344 /* if we haven't initialized - init (automatic abort if already done) */
1345 evas_common_cpu_init();
1346 evas_common_blend_init();
1347 evas_common_image_init();
1348 evas_common_convert_init();
1349 evas_common_scale_init();
1350 evas_common_rectangle_init();
1351 evas_common_gradient_init();
1352 evas_common_polygon_init();
1353 evas_common_line_init();
1354 evas_common_font_init();
1355 evas_common_draw_init();
1356 evas_common_tilebuf_init();
1357
1358 if (w <= 0) w = 640;
1359 if (h <= 0) h = 480;
1360
1361 /* GL Initialization */
1362#ifdef HAVE_SDL_GL_CONTEXT_VERSION
1363 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
1364 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
1365#endif
1366 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
1367 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
1368 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
1369 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
1370 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
1371 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
1372
1373 surface = SDL_SetVideoMode(w, h, 32, EVAS_SDL_GL_FLAG
1374 | (fullscreen ? SDL_FULLSCREEN : 0)
1375 | (noframe ? SDL_NOFRAME : 0));
1376
1377 if (!surface)
1378 {
1379 CRIT("SDL_SetVideoMode [ %i x %i x 32 ] failed.", w, h);
1380 exit(-1);
1381 }
1382
1383 re->gl_context = evas_gl_common_context_new();
1384 if (!re->gl_context)
1385 {
1386 free(re);
1387 return NULL;
1388 }
1389 evas_gl_common_context_use(re->gl_context);
1390 evas_gl_common_context_resize(re->gl_context, w, h);
1391
1392 /* End GL Initialization */
1393 re->w = w;
1394 re->h = h;
1395 return re;
1396}
1397