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