1 #include "evas_engine.h"
2 #include "Evas_Engine_GL_Glew.h"
5 /* function tables - filled in later (func and parent func) */
6 static Evas_Func func, pfunc;
8 typedef struct _Render_Engine Render_Engine;
15 Evas_GL_Glew_Window *window;
22 Evas_Engine_Info_GL_Glew *info;
24 info = calloc(1, sizeof(Evas_Engine_Info_GL_Glew));
25 if (!info) return NULL;
27 info->magic.magic = rand();
34 eng_info_free(Evas *e, void *info)
36 Evas_Engine_Info_GL_Glew *in;
38 in = (Evas_Engine_Info_GL_Glew *)info;
43 eng_setup(Evas *e, void *in)
46 Evas_Engine_Info_GL_Glew *info;
48 info = (Evas_Engine_Info_GL_Glew *)in;
49 if (!e->engine.data.output)
51 re = calloc(1, sizeof(Render_Engine));
54 if (!evas_glew_init(info->info.window, &re->dc, &re->context))
57 e->engine.data.output = NULL;
61 re->win = info->info.window;
62 e->engine.data.output = re;
63 re->window = eng_window_new(info->info.window,
72 e->engine.data.output = NULL;
76 evas_common_cpu_init();
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();
93 if (!evas_glew_init(info->info.window, &re->dc, &re->context))
96 e->engine.data.output = NULL;
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,
110 if (!e->engine.data.output) return;
112 if (!e->engine.data.context)
113 e->engine.data.context =
114 e->engine.func->context_new(e->engine.data.output);
118 eng_output_free(void *data)
122 re = (Render_Engine *)data;
123 eng_window_free(re->window);
124 evas_glew_shutdown(re->win, re->dc, re->context);
127 evas_common_font_shutdown();
128 evas_common_image_shutdown();
132 eng_output_resize(void *data, int w, int h)
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);
143 eng_output_tile_size_set(void *data, int w, int h)
147 re = (Render_Engine *)data;
151 eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
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)
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;
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;
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;
179 re->window->draw.redraw = 1;
183 eng_output_redraws_rect_del(void *data, int x, int y, int w, int h)
187 re = (Render_Engine *)data;
191 eng_output_redraws_clear(void *data)
195 re = (Render_Engine *)data;
196 re->window->draw.redraw = 0;
199 #define SLOW_GL_COPY_RECT 1
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)
206 re = (Render_Engine *)data;
207 /* get the upate rect surface - return engine data as dummy */
208 if (!re->window->draw.redraw)
210 // printf("GL: NO updates!\n");
213 // printf("GL: update....!\n");
214 #ifdef SLOW_GL_COPY_RECT
215 /* if any update - just return the whole canvas - works with swap
219 if (w) *w = re->window->width;
220 if (h) *h = re->window->height;
223 if (cw) *cw = re->window->width;
224 if (ch) *ch = re->window->height;
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
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;
245 eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h)
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;
256 eng_output_flush(void *data)
260 re = (Render_Engine *)data;
261 if (!re->window->draw.drew) return;
263 re->window->draw.drew = 0;
264 eng_window_use(re->window);
266 #ifdef SLOW_GL_COPY_RECT
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);
278 eng_output_idle_flush(void *data)
282 re = (Render_Engine *)data;
286 eng_context_cutout_add(void *data, void *context, int x, int y, int w, int h)
290 re = (Render_Engine *)data;
291 /* not used in gl engine */
295 eng_context_cutout_clear(void *data, void *context)
299 re = (Render_Engine *)data;
300 /* not used in gl engine */
304 eng_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h)
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);
315 eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2)
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);
325 eng_polygon_point_add(void *data, void *context, void *polygon, int x, int y)
329 re = (Render_Engine *)data;
330 return evas_gl_common_poly_point_add(polygon, x, y);
335 eng_polygon_points_clear(void *data, void *context, void *polygon)
339 re = (Render_Engine *)data;
340 return evas_gl_common_poly_points_clear(polygon);
344 eng_polygon_draw(void *data, void *context, void *surface, void *polygon)
348 re = (Render_Engine *)data;
349 re->window->gl_context->dc = context;
350 evas_gl_common_poly_draw(re->window->gl_context, polygon);
354 eng_gradient_new(void *data)
356 return evas_gl_common_gradient_new();
360 eng_gradient_color_stop_add(void *data, void *gradient, int r, int g, int b, int a, int delta)
362 evas_gl_common_gradient_color_stop_add(gradient, r, g, b, a, delta);
366 eng_gradient_alpha_stop_add(void *data, void *gradient, int a, int delta)
368 evas_gl_common_gradient_alpha_stop_add(gradient, a, delta);
372 eng_gradient_clear(void *data, void *gradient)
374 evas_gl_common_gradient_clear(gradient);
378 eng_gradient_color_data_set(void *data, void *gradient, void *map, int len, int has_alpha)
380 evas_gl_common_gradient_color_data_set(gradient, map, len, has_alpha);
384 eng_gradient_alpha_data_set(void *data, void *gradient, void *alpha_map, int len)
386 evas_gl_common_gradient_alpha_data_set(gradient, alpha_map, len);
390 eng_gradient_free(void *data, void *gradient)
392 evas_gl_common_gradient_free(gradient);
396 eng_gradient_fill_set(void *data, void *gradient, int x, int y, int w, int h)
398 evas_gl_common_gradient_fill_set(gradient, x, y, w, h);
402 eng_gradient_fill_angle_set(void *data, void *gradient, double angle)
404 evas_gl_common_gradient_fill_angle_set(gradient, angle);
408 eng_gradient_fill_spread_set(void *data, void *gradient, int spread)
410 evas_gl_common_gradient_fill_spread_set(gradient, spread);
414 eng_gradient_angle_set(void *data, void *gradient, double angle)
416 evas_gl_common_gradient_map_angle_set(gradient, angle);
420 eng_gradient_offset_set(void *data, void *gradient, float offset)
422 evas_gl_common_gradient_map_offset_set(gradient, offset);
426 eng_gradient_direction_set(void *data, void *gradient, int direction)
428 evas_gl_common_gradient_map_direction_set(gradient, direction);
432 eng_gradient_type_set(void *data, void *gradient, char *name, char *params)
434 evas_gl_common_gradient_type_set(gradient, name, params);
438 eng_gradient_is_opaque(void *data, void *context, void *gradient, int x, int y, int w, int h)
440 Render_Engine *re = (Render_Engine *)data;
442 re->window->gl_context->dc = context;
443 return evas_gl_common_gradient_is_opaque(re->window->gl_context, gradient, x, y, w, h);
447 eng_gradient_is_visible(void *data, void *context, void *gradient, int x, int y, int w, int h)
449 Render_Engine *re = (Render_Engine *)data;
451 re->window->gl_context->dc = context;
452 return evas_gl_common_gradient_is_visible(re->window->gl_context, gradient, x, y, w, h);
456 eng_gradient_render_pre(void *data, void *context, void *gradient)
458 Render_Engine *re = (Render_Engine *)data;
460 re->window->gl_context->dc = context;
461 evas_gl_common_gradient_render_pre(re->window->gl_context, gradient);
465 eng_gradient_render_post(void *data, void *gradient)
467 evas_gl_common_gradient_render_post(gradient);
471 eng_gradient_draw(void *data, void *context, void *surface, void *gradient, int x, int y, int w, int h)
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);
482 eng_image_alpha_get(void *data, void *image)
487 re = (Render_Engine *)data;
488 if (!image) return 1;
490 /* FIXME: can move to gl_common */
491 switch (im->cs.space)
493 case EVAS_COLORSPACE_ARGB8888:
494 if (im->im->cache_entry.flags.alpha) return 1;
502 eng_image_colorspace_get(void *data, void *image)
507 re = (Render_Engine *)data;
508 if (!image) return EVAS_COLORSPACE_ARGB8888;
514 eng_image_alpha_set(void *data, void *image, int has_alpha)
519 re = (Render_Engine *)data;
520 if (!image) return NULL;
521 eng_window_use(re->window);
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)
529 Evas_GL_Image *im_new;
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);
539 evas_gl_common_image_dirty(im);
540 im->im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
545 eng_image_border_set(void *data, void *image, int l, int r, int t, int b)
549 re = (Render_Engine *)data;
554 eng_image_border_get(void *data, void *image, int *l, int *r, int *t, int *b)
558 re = (Render_Engine *)data;
562 eng_image_comment_get(void *data, void *image, char *key)
567 re = (Render_Engine *)data;
568 if (!image) return NULL;
570 return im->im->info.comment;
574 eng_image_format_get(void *data, void *image)
579 re = (Render_Engine *)data;
585 eng_image_colorspace_set(void *data, void *image, int cspace)
590 re = (Render_Engine *)data;
593 /* FIXME: can move to gl_common */
594 if (im->cs.space == cspace) return;
595 evas_cache_image_colorspace(&im->im->cache_entry, cspace);
598 case EVAS_COLORSPACE_ARGB8888:
601 if (!im->cs.no_free) free(im->cs.data);
606 case EVAS_COLORSPACE_YCBCR422P601_PL:
607 case EVAS_COLORSPACE_YCBCR422P709_PL:
608 if (im->tex) evas_gl_common_texture_free(im->tex);
612 if (!im->cs.no_free) free(im->cs.data);
614 im->cs.data = calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
621 im->cs.space = cspace;
625 eng_image_native_set(void *data, void *image, void *native)
630 eng_image_native_get(void *data, void *image)
636 eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
640 re = (Render_Engine *)data;
642 eng_window_use(re->window);
643 return evas_gl_common_image_load(re->window->gl_context, file, key, lo);
647 eng_image_new_from_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
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);
657 eng_image_new_from_copied_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
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);
667 eng_image_free(void *data, void *image)
671 re = (Render_Engine *)data;
673 eng_window_use(re->window);
674 evas_gl_common_image_free(image);
678 eng_image_size_get(void *data, void *image, int *w, int *h)
682 re = (Render_Engine *)data;
689 if (w) *w = ((Evas_GL_Image *)image)->im->cache_entry.w;
690 if (h) *h = ((Evas_GL_Image *)image)->im->cache_entry.h;
695 eng_image_size_set(void *data, void *image, int w, int h)
698 Evas_GL_Image *im, *im_old;
700 re = (Render_Engine *)data;
701 if (!image) return NULL;
702 eng_window_use(re->window);
704 if ((eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P601_PL) ||
705 (eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P709_PL))
707 if ((im_old) && (im_old->im->cache_entry.w == w) && (im_old->im->cache_entry.h == h))
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));
716 evas_common_load_image_data_from_file(im_old->im);
717 if (im_old->im->image->data)
719 evas_common_blit_rectangle(im_old->im, im->im, 0, 0, w, h, 0, 0);
720 evas_common_cpu_end_opt();
723 evas_gl_common_image_free(im_old);
726 im = evas_gl_common_image_new(re->window->gl_context, w, h, 1, EVAS_COLORSPACE_ARGB8888);
731 eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
735 re = (Render_Engine *)data;
736 if (!image) return NULL;
737 evas_gl_common_image_dirty(image);
742 eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data)
747 re = (Render_Engine *)data;
754 eng_window_use(re->window);
755 evas_cache_image_load_data(&im->im->cache_entry);
756 switch (im->cs.space)
758 case EVAS_COLORSPACE_ARGB8888:
761 if (im->references > 1)
763 Evas_GL_Image *im_new;
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));
773 evas_gl_common_image_free(im);
777 evas_gl_common_image_dirty(im);
779 *image_data = im->im->image.data;
781 case EVAS_COLORSPACE_YCBCR422P601_PL:
782 case EVAS_COLORSPACE_YCBCR422P709_PL:
783 *image_data = im->cs.data;
793 eng_image_data_put(void *data, void *image, DATA32 *image_data)
796 Evas_GL_Image *im, *im2;
798 re = (Render_Engine *)data;
799 if (!image) return NULL;
801 eng_window_use(re->window);
802 switch (im->cs.space)
804 case EVAS_COLORSPACE_ARGB8888:
805 if (image_data != im->im->image.data)
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));
815 evas_gl_common_image_free(im);
819 case EVAS_COLORSPACE_YCBCR422P601_PL:
820 case EVAS_COLORSPACE_YCBCR422P709_PL:
821 if (image_data != im->cs.data)
825 if (!im->cs.no_free) free(im->cs.data);
827 im->cs.data = image_data;
834 /* hmmm - but if we wrote... why bother? */
835 evas_gl_common_image_dirty(im);
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)
844 re = (Render_Engine *)data;
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,
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)
859 re = (Render_Engine *)data;
861 static RGBA_Image *im = NULL;
864 im = (RGBA_Image *) evas_cache_image_empty(evas_common_image_cache_get());
866 evas_cache_image_surface_alloc(&im->cache_entry, re->window->width, re->window->height);
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,
884 module_open(Evas_Module *em)
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 */
891 /* now to override methods */
892 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
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);
907 ORD(output_idle_flush);
910 ORD(polygon_point_add);
911 ORD(polygon_points_clear);
915 ORD(gradient_color_stop_add);
916 ORD(gradient_alpha_stop_add);
917 ORD(gradient_color_data_set);
918 ORD(gradient_alpha_data_set);
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);
933 ORD(image_new_from_data);
934 ORD(image_new_from_copied_data);
938 ORD(image_dirty_region);
941 ORD(image_alpha_set);
942 ORD(image_alpha_get);
943 ORD(image_border_set);
944 ORD(image_border_get);
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);
953 /* now advertise out own api */
954 em->functions = (void *)(&func);
964 EAPI Evas_Module_Api evas_modapi =
966 EVAS_MODULE_API_VERSION,
967 EVAS_MODULE_TYPE_ENGINE,