move around - flatter.
[profile/ivi/evas.git] / src / modules / engines / gl_glew / evas_engine.c
1 #include "evas_engine.h"
2 #include "Evas_Engine_GL_Glew.h"
3
4
5 /* function tables - filled in later (func and parent func) */
6 static Evas_Func func, pfunc;
7
8 typedef struct _Render_Engine Render_Engine;
9
10 struct _Render_Engine
11 {
12    HWND                 win;
13    HDC                  dc;
14    HGLRC                context;
15    Evas_GL_Glew_Window *window;
16    int                  end;
17 };
18
19 static void *
20 eng_info(Evas *e)
21 {
22    Evas_Engine_Info_GL_Glew *info;
23
24    info = calloc(1, sizeof(Evas_Engine_Info_GL_Glew));
25    if (!info) return NULL;
26
27    info->magic.magic = rand();
28
29    return info;
30    e = NULL;
31 }
32
33 static void
34 eng_info_free(Evas *e, void *info)
35 {
36    Evas_Engine_Info_GL_Glew *in;
37
38    in = (Evas_Engine_Info_GL_Glew *)info;
39    free(in);
40 }
41
42 static void
43 eng_setup(Evas *e, void *in)
44 {
45    Render_Engine            *re;
46    Evas_Engine_Info_GL_Glew *info;
47
48    info = (Evas_Engine_Info_GL_Glew *)in;
49    if (!e->engine.data.output)
50      {
51         re = calloc(1, sizeof(Render_Engine));
52         if (!re) return;
53
54         if (!evas_glew_init(info->info.window, &re->dc, &re->context))
55           {
56              free(re);
57              e->engine.data.output = NULL;
58              return;
59           }
60
61         re->win = info->info.window;
62         e->engine.data.output = re;
63         re->window = eng_window_new(info->info.window,
64                                     re->dc,
65                                     re->context,
66                                     info->info.depth,
67                                     e->output.w,
68                                     e->output.h);
69         if (!re->window)
70           {
71              free(re);
72              e->engine.data.output = NULL;
73              return;
74           }
75
76         evas_common_cpu_init();
77
78         evas_common_blend_init();
79         evas_common_image_init();
80         evas_common_convert_init();
81         evas_common_scale_init();
82         evas_common_rectangle_init();
83         evas_common_gradient_init();
84         evas_common_polygon_init();
85         evas_common_line_init();
86         evas_common_font_init();
87         evas_common_draw_init();
88         evas_common_tilebuf_init();
89      }
90    else
91      {
92
93         if (!evas_glew_init(info->info.window, &re->dc, &re->context))
94           {
95              free(re);
96              e->engine.data.output = NULL;
97              return;
98           }
99
100         re->win = info->info.window;
101         re = e->engine.data.output;
102         eng_window_free(re->window);
103         re->window = eng_window_new(info->info.window,
104                                     re->dc,
105                                     re->context,
106                                     info->info.depth,
107                                     e->output.w,
108                                     e->output.h);
109      }
110    if (!e->engine.data.output) return;
111
112    if (!e->engine.data.context)
113      e->engine.data.context =
114        e->engine.func->context_new(e->engine.data.output);
115 }
116
117 static void
118 eng_output_free(void *data)
119 {
120    Render_Engine *re;
121
122    re = (Render_Engine *)data;
123    eng_window_free(re->window);
124    evas_glew_shutdown(re->win, re->dc, re->context);
125    free(re);
126
127    evas_common_font_shutdown();
128    evas_common_image_shutdown();
129 }
130
131 static void
132 eng_output_resize(void *data, int w, int h)
133 {
134    Render_Engine *re;
135
136    re = (Render_Engine *)data;
137    re->window->width = w;
138    re->window->height = h;
139    evas_gl_common_context_resize(re->window->gl_context, w, h);
140 }
141
142 static void
143 eng_output_tile_size_set(void *data, int w, int h)
144 {
145    Render_Engine *re;
146
147    re = (Render_Engine *)data;
148 }
149
150 static void
151 eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
152 {
153    Render_Engine *re;
154
155    re = (Render_Engine *)data;
156    evas_gl_common_context_resize(re->window->gl_context, re->window->width, re->window->height);
157    /* simple bounding box */
158    if (!re->window->draw.redraw)
159      {
160 #if 0
161         re->window->draw.x1 = x;
162         re->window->draw.y1 = y;
163         re->window->draw.x2 = x + w - 1;
164         re->window->draw.y2 = y + h - 1;
165 #else
166         re->window->draw.x1 = 0;
167         re->window->draw.y1 = 0;
168         re->window->draw.x2 = re->window->width - 1;
169         re->window->draw.y2 = re->window->height - 1;
170 #endif
171      }
172    else
173      {
174         if (x < re->window->draw.x1) re->window->draw.x1 = x;
175         if (y < re->window->draw.y1) re->window->draw.y1 = y;
176         if ((x + w - 1) > re->window->draw.x2) re->window->draw.x2 = x + w - 1;
177         if ((y + h - 1) > re->window->draw.y2) re->window->draw.y2 = y + h - 1;
178      }
179    re->window->draw.redraw = 1;
180 }
181
182 static void
183 eng_output_redraws_rect_del(void *data, int x, int y, int w, int h)
184 {
185    Render_Engine *re;
186
187    re = (Render_Engine *)data;
188 }
189
190 static void
191 eng_output_redraws_clear(void *data)
192 {
193    Render_Engine *re;
194
195    re = (Render_Engine *)data;
196    re->window->draw.redraw = 0;
197 }
198
199 #define SLOW_GL_COPY_RECT 1
200
201 static void *
202 eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
203 {
204    Render_Engine *re;
205
206    re = (Render_Engine *)data;
207    /* get the upate rect surface - return engine data as dummy */
208    if (!re->window->draw.redraw)
209      {
210 //      printf("GL: NO updates!\n");
211         return NULL;
212      }
213 //   printf("GL: update....!\n");
214 #ifdef SLOW_GL_COPY_RECT
215    /* if any update - just return the whole canvas - works with swap
216     * buffers then */
217    if (x) *x = 0;
218    if (y) *y = 0;
219    if (w) *w = re->window->width;
220    if (h) *h = re->window->height;
221    if (cx) *cx = 0;
222    if (cy) *cy = 0;
223    if (cw) *cw = re->window->width;
224    if (ch) *ch = re->window->height;
225 #else
226    /* 1 update - INCREDIBLY SLOW if combined with swap_rect in flush. a gl
227     * problem where there just is no hardware path for somethnig that
228     * obviously SHOULD be there */
229    /* only 1 update to minimise gl context games and rendering multiple update
230     * regions as evas does with other engines
231     */
232    if (x) *x = re->window->draw.x1;
233    if (y) *y = re->window->draw.y1;
234    if (w) *w = re->window->draw.x2 - re->window->draw.x1 + 1;
235    if (h) *h = re->window->draw.y2 - re->window->draw.y1 + 1;
236    if (cx) *cx = re->window->draw.x1;
237    if (cy) *cy = re->window->draw.y1;
238    if (cw) *cw = re->window->draw.x2 - re->window->draw.x1 + 1;
239    if (ch) *ch = re->window->draw.y2 - re->window->draw.y1 + 1;
240 #endif
241    return re;
242 }
243
244 static void
245 eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h)
246 {
247    Render_Engine *re;
248
249    re = (Render_Engine *)data;
250    /* put back update surface.. in this case just unflag redraw */
251    re->window->draw.redraw = 0;
252    re->window->draw.drew = 1;
253 }
254
255 static void
256 eng_output_flush(void *data)
257 {
258    Render_Engine *re;
259
260    re = (Render_Engine *)data;
261    if (!re->window->draw.drew) return;
262
263    re->window->draw.drew = 0;
264    eng_window_use(re->window);
265
266 #ifdef SLOW_GL_COPY_RECT
267    SwapBuffers(re->dc);
268 #else
269    /* SLOW AS ALL HELL */
270    evas_gl_common_swap_rect(re->window->gl_context,
271                             re->window->draw.x1, re->window->draw.y1,
272                             re->window->draw.x2 - re->window->draw.x1 + 1,
273                             re->window->draw.y2 - re->window->draw.y1 + 1);
274 #endif
275 }
276
277 static void
278 eng_output_idle_flush(void *data)
279 {
280    Render_Engine *re;
281
282    re = (Render_Engine *)data;
283 }
284
285 static void
286 eng_context_cutout_add(void *data, void *context, int x, int y, int w, int h)
287 {
288    Render_Engine *re;
289
290    re = (Render_Engine *)data;
291    /* not used in gl engine */
292 }
293
294 static void
295 eng_context_cutout_clear(void *data, void *context)
296 {
297    Render_Engine *re;
298
299    re = (Render_Engine *)data;
300    /* not used in gl engine */
301 }
302
303 static void
304 eng_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h)
305 {
306    Render_Engine *re;
307
308    re = (Render_Engine *)data;
309    eng_window_use(re->window);
310    re->window->gl_context->dc = context;
311    evas_gl_common_rect_draw(re->window->gl_context, x, y, w, h);
312 }
313
314 static void
315 eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2)
316 {
317    Render_Engine *re;
318
319    re = (Render_Engine *)data;
320    re->window->gl_context->dc = context;
321    evas_gl_common_line_draw(re->window->gl_context, x1, y1, x2, y2);
322 }
323
324 static void *
325 eng_polygon_point_add(void *data, void *context, void *polygon, int x, int y)
326 {
327    Render_Engine *re;
328
329    re = (Render_Engine *)data;
330    return evas_gl_common_poly_point_add(polygon, x, y);
331
332 }
333
334 static void *
335 eng_polygon_points_clear(void *data, void *context, void *polygon)
336 {
337    Render_Engine *re;
338
339    re = (Render_Engine *)data;
340    return evas_gl_common_poly_points_clear(polygon);
341 }
342
343 static void
344 eng_polygon_draw(void *data, void *context, void *surface, void *polygon)
345 {
346    Render_Engine *re;
347
348    re = (Render_Engine *)data;
349    re->window->gl_context->dc = context;
350    evas_gl_common_poly_draw(re->window->gl_context, polygon);
351 }
352
353 static void *
354 eng_gradient_new(void *data)
355 {
356    return evas_gl_common_gradient_new();
357 }
358
359 static void
360 eng_gradient_color_stop_add(void *data, void *gradient, int r, int g, int b, int a, int delta)
361 {
362    evas_gl_common_gradient_color_stop_add(gradient, r, g, b, a, delta);
363 }
364
365 static void
366 eng_gradient_alpha_stop_add(void *data, void *gradient, int a, int delta)
367 {
368    evas_gl_common_gradient_alpha_stop_add(gradient, a, delta);
369 }
370
371 static void
372 eng_gradient_clear(void *data, void *gradient)
373 {
374    evas_gl_common_gradient_clear(gradient);
375 }
376
377 static void
378 eng_gradient_color_data_set(void *data, void *gradient, void *map, int len, int has_alpha)
379 {
380    evas_gl_common_gradient_color_data_set(gradient, map, len, has_alpha);
381 }
382
383 static void
384 eng_gradient_alpha_data_set(void *data, void *gradient, void *alpha_map, int len)
385 {
386    evas_gl_common_gradient_alpha_data_set(gradient, alpha_map, len);
387 }
388
389 static void
390 eng_gradient_free(void *data, void *gradient)
391 {
392    evas_gl_common_gradient_free(gradient);
393 }
394
395 static void
396 eng_gradient_fill_set(void *data, void *gradient, int x, int y, int w, int h)
397 {
398    evas_gl_common_gradient_fill_set(gradient, x, y, w, h);
399 }
400
401 static void
402 eng_gradient_fill_angle_set(void *data, void *gradient, double angle)
403 {
404    evas_gl_common_gradient_fill_angle_set(gradient, angle);
405 }
406
407 static void
408 eng_gradient_fill_spread_set(void *data, void *gradient, int spread)
409 {
410    evas_gl_common_gradient_fill_spread_set(gradient, spread);
411 }
412
413 static void
414 eng_gradient_angle_set(void *data, void *gradient, double angle)
415 {
416    evas_gl_common_gradient_map_angle_set(gradient, angle);
417 }
418
419 static void
420 eng_gradient_offset_set(void *data, void *gradient, float offset)
421 {
422    evas_gl_common_gradient_map_offset_set(gradient, offset);
423 }
424
425 static void
426 eng_gradient_direction_set(void *data, void *gradient, int direction)
427 {
428    evas_gl_common_gradient_map_direction_set(gradient, direction);
429 }
430
431 static void
432 eng_gradient_type_set(void *data, void *gradient, char *name, char *params)
433 {
434    evas_gl_common_gradient_type_set(gradient, name, params);
435 }
436
437 static int
438 eng_gradient_is_opaque(void *data, void *context, void *gradient, int x, int y, int w, int h)
439 {
440    Render_Engine *re = (Render_Engine *)data;
441
442    re->window->gl_context->dc = context;
443    return evas_gl_common_gradient_is_opaque(re->window->gl_context, gradient, x, y, w, h);
444 }
445
446 static int
447 eng_gradient_is_visible(void *data, void *context, void *gradient, int x, int y, int w, int h)
448 {
449    Render_Engine *re = (Render_Engine *)data;
450
451    re->window->gl_context->dc = context;
452    return evas_gl_common_gradient_is_visible(re->window->gl_context, gradient, x, y, w, h);
453 }
454
455 static void
456 eng_gradient_render_pre(void *data, void *context, void *gradient)
457 {
458    Render_Engine *re = (Render_Engine *)data;
459
460    re->window->gl_context->dc = context;
461    evas_gl_common_gradient_render_pre(re->window->gl_context, gradient);
462 }
463
464 static void
465 eng_gradient_render_post(void *data, void *gradient)
466 {
467    evas_gl_common_gradient_render_post(gradient);
468 }
469
470 static void
471 eng_gradient_draw(void *data, void *context, void *surface, void *gradient, int x, int y, int w, int h)
472 {
473    Render_Engine *re;
474
475    re = (Render_Engine *)data;
476    eng_window_use(re->window);
477    re->window->gl_context->dc = context;
478    evas_gl_common_gradient_draw(re->window->gl_context, gradient, x, y, w, h);
479 }
480
481 static int
482 eng_image_alpha_get(void *data, void *image)
483 {
484    Render_Engine *re;
485    Evas_GL_Image *im;
486
487    re = (Render_Engine *)data;
488    if (!image) return 1;
489    im = image;
490    /* FIXME: can move to gl_common */
491    switch (im->cs.space)
492      {
493       case EVAS_COLORSPACE_ARGB8888:
494         if (im->im->cache_entry.flags.alpha) return 1;
495       default:
496         break;
497      }
498    return 0;
499 }
500
501 static int
502 eng_image_colorspace_get(void *data, void *image)
503 {
504    Render_Engine *re;
505    Evas_GL_Image *im;
506
507    re = (Render_Engine *)data;
508    if (!image) return EVAS_COLORSPACE_ARGB8888;
509    im = image;
510    return im->cs.space;
511 }
512
513 static void *
514 eng_image_alpha_set(void *data, void *image, int has_alpha)
515 {
516    Render_Engine *re;
517    Evas_GL_Image *im;
518
519    re = (Render_Engine *)data;
520    if (!image) return NULL;
521    eng_window_use(re->window);
522    im = image;
523    /* FIXME: can move to gl_common */
524    if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im;
525    if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image;
526    else if ((!has_alpha) && (!im->im->cache_entry.flags.alpha)) return image;
527    if (im->references > 1)
528     {
529         Evas_GL_Image *im_new;
530
531         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,
532                                                            eng_image_alpha_get(data, image),
533                                                            eng_image_colorspace_get(data, image));
534         if (!im_new) return im;
535         evas_gl_common_image_free(im);
536         im = im_new;
537      }
538    else
539      evas_gl_common_image_dirty(im);
540    im->im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
541    return image;
542 }
543
544 static void *
545 eng_image_border_set(void *data, void *image, int l, int r, int t, int b)
546 {
547    Render_Engine *re;
548
549    re = (Render_Engine *)data;
550    return image;
551 }
552
553 static void
554 eng_image_border_get(void *data, void *image, int *l, int *r, int *t, int *b)
555 {
556    Render_Engine *re;
557
558    re = (Render_Engine *)data;
559 }
560
561 static char *
562 eng_image_comment_get(void *data, void *image, char *key)
563 {
564    Render_Engine *re;
565    Evas_GL_Image *im;
566
567    re = (Render_Engine *)data;
568    if (!image) return NULL;
569    im = image;
570    return im->im->info.comment;
571 }
572
573 static char *
574 eng_image_format_get(void *data, void *image)
575 {
576    Render_Engine *re;
577    Evas_GL_Image *im;
578
579    re = (Render_Engine *)data;
580    im = image;
581    return NULL;
582 }
583
584 static void
585 eng_image_colorspace_set(void *data, void *image, int cspace)
586 {
587    Render_Engine *re;
588    Evas_GL_Image *im;
589
590    re = (Render_Engine *)data;
591    if (!image) return;
592    im = image;
593    /* FIXME: can move to gl_common */
594    if (im->cs.space == cspace) return;
595    evas_cache_image_colorspace(&im->im->cache_entry, cspace);
596    switch (cspace)
597      {
598       case EVAS_COLORSPACE_ARGB8888:
599         if (im->cs.data)
600           {
601              if (!im->cs.no_free) free(im->cs.data);
602              im->cs.data = NULL;
603              im->cs.no_free = 0;
604           }
605         break;
606       case EVAS_COLORSPACE_YCBCR422P601_PL:
607       case EVAS_COLORSPACE_YCBCR422P709_PL:
608         if (im->tex) evas_gl_common_texture_free(im->tex);
609         im->tex = NULL;
610         if (im->cs.data)
611           {
612              if (!im->cs.no_free) free(im->cs.data);
613           }
614         im->cs.data = calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
615         im->cs.no_free = 0;
616         break;
617       default:
618         abort();
619         break;
620      }
621    im->cs.space = cspace;
622 }
623
624 static void
625 eng_image_native_set(void *data, void *image, void *native)
626 {
627 }
628
629 static void *
630 eng_image_native_get(void *data, void *image)
631 {
632    return NULL;
633 }
634
635 static void *
636 eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
637 {
638    Render_Engine *re;
639
640    re = (Render_Engine *)data;
641    *error = 0;
642    eng_window_use(re->window);
643    return evas_gl_common_image_load(re->window->gl_context, file, key, lo);
644 }
645
646 static void *
647 eng_image_new_from_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
648 {
649    Render_Engine *re;
650
651    re = (Render_Engine *)data;
652    eng_window_use(re->window);
653    return evas_gl_common_image_new_from_data(re->window->gl_context, w, h, image_data, alpha, cspace);
654 }
655
656 static void *
657 eng_image_new_from_copied_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
658 {
659    Render_Engine *re;
660
661    re = (Render_Engine *)data;
662    eng_window_use(re->window);
663    return evas_gl_common_image_new_from_copied_data(re->window->gl_context, w, h, image_data, alpha, cspace);
664 }
665
666 static void
667 eng_image_free(void *data, void *image)
668 {
669    Render_Engine *re;
670
671    re = (Render_Engine *)data;
672    if (!image) return;
673    eng_window_use(re->window);
674    evas_gl_common_image_free(image);
675 }
676
677 static void
678 eng_image_size_get(void *data, void *image, int *w, int *h)
679 {
680    Render_Engine *re;
681
682    re = (Render_Engine *)data;
683    if (!image)
684      {
685         *w = 0;
686         *h = 0;
687         return;
688      }
689    if (w) *w = ((Evas_GL_Image *)image)->im->cache_entry.w;
690    if (h) *h = ((Evas_GL_Image *)image)->im->cache_entry.h;
691
692 }
693
694 static void *
695 eng_image_size_set(void *data, void *image, int w, int h)
696 {
697    Render_Engine *re;
698    Evas_GL_Image *im, *im_old;
699
700    re = (Render_Engine *)data;
701    if (!image) return NULL;
702    eng_window_use(re->window);
703    im_old = image;
704    if ((eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P601_PL) ||
705        (eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P709_PL))
706      w &= ~0x1;
707    if ((im_old) && (im_old->im->cache_entry.w == w) && (im_old->im->cache_entry.h == h))
708
709      return image;
710    if (im_old)
711      {
712         im = evas_gl_common_image_new(re->window->gl_context, w, h,
713                                       eng_image_alpha_get(data, image),
714                                       eng_image_colorspace_get(data, image));
715 /*
716         evas_common_load_image_data_from_file(im_old->im);
717         if (im_old->im->image->data)
718           {
719              evas_common_blit_rectangle(im_old->im, im->im, 0, 0, w, h, 0, 0);
720              evas_common_cpu_end_opt();
721           }
722  */
723         evas_gl_common_image_free(im_old);
724      }
725    else
726      im = evas_gl_common_image_new(re->window->gl_context, w, h, 1, EVAS_COLORSPACE_ARGB8888);
727    return im;
728 }
729
730 static void *
731 eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
732 {
733    Render_Engine *re;
734
735    re = (Render_Engine *)data;
736    if (!image) return NULL;
737    evas_gl_common_image_dirty(image);
738    return image;
739 }
740
741 static void *
742 eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data)
743 {
744    Render_Engine *re;
745    Evas_GL_Image *im;
746
747    re = (Render_Engine *)data;
748    if (!image)
749      {
750         *image_data = NULL;
751         return NULL;
752      }
753    im = image;
754    eng_window_use(re->window);
755    evas_cache_image_load_data(&im->im->cache_entry);
756    switch (im->cs.space)
757      {
758       case EVAS_COLORSPACE_ARGB8888:
759         if (to_write)
760           {
761              if (im->references > 1)
762                {
763                   Evas_GL_Image *im_new;
764
765                   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,
766                                                                      eng_image_alpha_get(data, image),
767                                                                      eng_image_colorspace_get(data, image));
768                   if (!im_new)
769                     {
770                        *image_data = NULL;
771                        return im;
772                     }
773                   evas_gl_common_image_free(im);
774                   im = im_new;
775                }
776              else
777                evas_gl_common_image_dirty(im);
778           }
779         *image_data = im->im->image.data;
780         break;
781       case EVAS_COLORSPACE_YCBCR422P601_PL:
782       case EVAS_COLORSPACE_YCBCR422P709_PL:
783         *image_data = im->cs.data;
784         break;
785       default:
786         abort();
787         break;
788      }
789    return im;
790 }
791
792 static void *
793 eng_image_data_put(void *data, void *image, DATA32 *image_data)
794 {
795    Render_Engine *re;
796    Evas_GL_Image *im, *im2;
797
798    re = (Render_Engine *)data;
799    if (!image) return NULL;
800    im = image;
801    eng_window_use(re->window);
802    switch (im->cs.space)
803      {
804       case EVAS_COLORSPACE_ARGB8888:
805         if (image_data != im->im->image.data)
806           {
807              int w, h;
808
809              w = im->im->cache_entry.w;
810              h = im->im->cache_entry.h;
811              im2 = eng_image_new_from_data(data, w, h, image_data,
812                                            eng_image_alpha_get(data, image),
813                                            eng_image_colorspace_get(data, image));
814              if (!im2) return im;
815              evas_gl_common_image_free(im);
816              im = im2;
817           }
818         break;
819       case EVAS_COLORSPACE_YCBCR422P601_PL:
820       case EVAS_COLORSPACE_YCBCR422P709_PL:
821         if (image_data != im->cs.data)
822           {
823              if (im->cs.data)
824                {
825                   if (!im->cs.no_free) free(im->cs.data);
826                }
827              im->cs.data = image_data;
828           }
829         break;
830       default:
831         abort();
832         break;
833      }
834    /* hmmm - but if we wrote... why bother? */
835    evas_gl_common_image_dirty(im);
836    return im;
837 }
838
839 static void
840 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)
841 {
842    Render_Engine *re;
843
844    re = (Render_Engine *)data;
845    if (!image) return;
846    eng_window_use(re->window);
847    re->window->gl_context->dc = context;
848    evas_gl_common_image_draw(re->window->gl_context, image,
849                              src_x, src_y, src_w, src_h,
850                              dst_x, dst_y, dst_w, dst_h,
851                              smooth);
852 }
853
854 static void
855 eng_font_draw(void *data, void *context, void *surface, void *font, int x, int y, int w, int h, int ow, int oh, const char *text)
856 {
857    Render_Engine *re;
858
859    re = (Render_Engine *)data;
860      {
861         static RGBA_Image *im = NULL;
862
863         if (!im)
864           im = (RGBA_Image *) evas_cache_image_empty(evas_common_image_cache_get());
865         if (!im) return ;
866         evas_cache_image_surface_alloc(&im->cache_entry, re->window->width, re->window->height);
867
868         evas_common_draw_context_font_ext_set(context,
869                                               re->window->gl_context,
870                                               evas_gl_font_texture_new,
871                                               evas_gl_font_texture_free,
872                                               evas_gl_font_texture_draw);
873         evas_common_font_draw(im, context, font, x, y, text);
874         evas_common_draw_context_font_ext_set(context,
875                                               NULL,
876                                               NULL,
877                                               NULL,
878                                               NULL);
879      }
880 }
881
882
883 EAPI int
884 module_open(Evas_Module *em)
885 {
886    if (!em) return 0;
887    /* get whatever engine module we inherit from */
888    if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
889    /* store it for later use */
890    func = pfunc;
891    /* now to override methods */
892    #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
893    ORD(info);
894    ORD(info_free);
895    ORD(setup);
896    ORD(output_free);
897    ORD(output_resize);
898    ORD(output_tile_size_set);
899    ORD(output_redraws_rect_add);
900    ORD(output_redraws_rect_del);
901    ORD(output_redraws_clear);
902    ORD(output_redraws_next_update_get);
903    ORD(output_redraws_next_update_push);
904    ORD(context_cutout_add);
905    ORD(context_cutout_clear);
906    ORD(output_flush);
907    ORD(output_idle_flush);
908    ORD(rectangle_draw);
909    ORD(line_draw);
910    ORD(polygon_point_add);
911    ORD(polygon_points_clear);
912    ORD(polygon_draw);
913    ORD(gradient_new);
914    ORD(gradient_free);
915    ORD(gradient_color_stop_add);
916    ORD(gradient_alpha_stop_add);
917    ORD(gradient_color_data_set);
918    ORD(gradient_alpha_data_set);
919    ORD(gradient_clear);
920    ORD(gradient_fill_set);
921    ORD(gradient_fill_angle_set);
922    ORD(gradient_fill_spread_set);
923    ORD(gradient_angle_set);
924    ORD(gradient_offset_set);
925    ORD(gradient_direction_set);
926    ORD(gradient_type_set);
927    ORD(gradient_is_opaque);
928    ORD(gradient_is_visible);
929    ORD(gradient_render_pre);
930    ORD(gradient_render_post);
931    ORD(gradient_draw);
932    ORD(image_load);
933    ORD(image_new_from_data);
934    ORD(image_new_from_copied_data);
935    ORD(image_free);
936    ORD(image_size_get);
937    ORD(image_size_set);
938    ORD(image_dirty_region);
939    ORD(image_data_get);
940    ORD(image_data_put);
941    ORD(image_alpha_set);
942    ORD(image_alpha_get);
943    ORD(image_border_set);
944    ORD(image_border_get);
945    ORD(image_draw);
946    ORD(image_comment_get);
947    ORD(image_format_get);
948    ORD(image_colorspace_set);
949    ORD(image_colorspace_get);
950    ORD(image_native_set);
951    ORD(image_native_get);
952    ORD(font_draw);
953    /* now advertise out own api */
954    em->functions = (void *)(&func);
955    return 1;
956 }
957
958 EAPI void
959 module_close(void)
960 {
961
962 }
963
964 EAPI Evas_Module_Api evas_modapi =
965 {
966    EVAS_MODULE_API_VERSION,
967    EVAS_MODULE_TYPE_ENGINE,
968    "gl_glew",
969    "none"
970 };