1 #include "evas_common.h"
2 #include "evas_engine.h"
4 #include <dlfcn.h> /* dlopen,dlclose,etc */
6 static void* _sdl_output_setup (int w, int h, int fullscreen, int noframe);
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;
15 Evas_Engine_Info_GL_SDL *info;
17 info = calloc(1, sizeof(Evas_Engine_Info_GL_SDL));
18 if (!info) return NULL;
19 info->magic.magic = rand();
24 eng_info_free(Evas *e __UNUSED__, void *info)
26 Evas_Engine_Info_GL_SDL *in;
27 in = (Evas_Engine_Info_GL_SDL *)info;
32 eng_setup(Evas *e, void *in)
35 Evas_Engine_Info_GL_SDL *info;
37 info = (Evas_Engine_Info_GL_SDL *)in;
39 SDL_Init(SDL_INIT_NOPARACHUTE);
41 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
43 ERR("SDL_Init failed with %s", SDL_GetError());
48 re = _sdl_output_setup(e->output.w, e->output.h,
49 info->flags.fullscreen,
52 e->engine.data.output = re;
53 if (!e->engine.data.output)
56 e->engine.func = &func;
57 e->engine.data.context = e->engine.func->context_new(e->engine.data.output);
63 eng_output_free(void *data)
67 re = (Render_Engine *)data;
68 evas_gl_common_context_free(re->gl_context);
71 evas_common_font_shutdown();
72 evas_common_image_shutdown();
74 SDL_QuitSubSystem(SDL_INIT_VIDEO);
78 eng_output_resize(void *data, int w, int h)
83 re = (Render_Engine *)data;
87 surface = SDL_SetVideoMode(w, h, 32, EVAS_SDL_GL_FLAG
88 | (re->info->flags.fullscreen ? SDL_FULLSCREEN : 0)
89 | (re->info->flags.noframe ? SDL_NOFRAME : 0));
92 ERR("Unable to change the resolution to : %ix%i", w, h);
96 evas_gl_common_context_resize(re->gl_context, w, h);
100 eng_output_tile_size_set(void *data, int w __UNUSED__, int h __UNUSED__)
102 // Render_Engine *re;
104 // re = (Render_Engine *)data;
108 eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
112 re = (Render_Engine *)data;
113 evas_gl_common_context_resize(re->gl_context, re->w, re->h);
114 /* smple bounding box */
115 if (!re->draw.redraw)
120 re->draw.x2 = x + w - 1;
121 re->draw.y2 = y + h - 1;
125 re->draw.x2 = re->w - 1;
126 re->draw.y2 = re->h - 1;
131 if (x < re->draw.x1) re->draw.x1 = x;
132 if (y < re->draw.y1) re->draw.y1 = y;
133 if ((x + w - 1) > re->draw.x2) re->draw.x2 = x + w - 1;
134 if ((y + h - 1) > re->draw.y2) re->draw.y2 = y + h - 1;
140 eng_output_redraws_rect_del(void *data, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
142 // Render_Engine *re;
144 // re = (Render_Engine *)data;
148 eng_output_redraws_clear(void *data)
152 re = (Render_Engine *)data;
154 // INF("GL: finish update cycle!");
157 /* at least the nvidia drivers are so abysmal that copying from the backbuffer
158 * to the front using glCopyPixels() that you literally can WATCH it draw the
159 * pixels slowly across the screen with a window update taking multiple
160 * seconds - so workaround by doing a full buffer render as frankly GL isn't
161 * up to doing anything that isn't done by quake (etc.)
163 #define SLOW_GL_COPY_RECT 1
164 /* vsync games - not for now though */
165 //#define VSYNC_TO_SCREEN 1
168 eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
172 re = (Render_Engine *)data;
173 evas_gl_common_context_flush(re->gl_context);
174 /* get the upate rect surface - return engine data as dummy */
175 if (!re->draw.redraw)
177 // printf("GL: NO updates!\n");
180 // printf("GL: update....!\n");
181 #ifdef SLOW_GL_COPY_RECT
182 /* if any update - just return the whole canvas - works with swap
193 /* 1 update - INCREDIBLY SLOW if combined with swap_rect in flush. a gl
194 * problem where there just is no hardware path for somethnig that
195 * obviously SHOULD be there */
196 /* only 1 update to minimise gl context games and rendering multiple update
197 * regions as evas does with other engines
199 if (x) *x = re->draw.x1;
200 if (y) *y = re->draw.y1;
201 if (w) *w = re->draw.x2 - re->draw.x1 + 1;
202 if (h) *h = re->draw.y2 - re->draw.y1 + 1;
203 if (cx) *cx = re->draw.x1;
204 if (cy) *cy = re->draw.y1;
205 if (cw) *cw = re->draw.x2 - re->draw.x1 + 1;
206 if (ch) *ch = re->draw.y2 - re->draw.y1 + 1;
208 // clear buffer. only needed for dest alpha
209 // glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
210 // glClear(GL_COLOR_BUFFER_BIT);
211 //x// printf("frame -> new\n");
212 return re->gl_context->def_surface;
216 eng_output_redraws_next_update_push(void *data, void *surface __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
220 re = (Render_Engine *)data;
221 /* put back update surface.. in this case just unflag redraw */
224 evas_gl_common_context_flush(re->gl_context);
225 //x// printf("frame -> push\n");
229 eng_output_flush(void *data)
233 re = (Render_Engine *)data;
234 if (!re->draw.drew) return;
235 //x// printf("frame -> flush\n");
239 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
241 eglSwapBuffers(re->egl_disp, re->egl_surface[0]);
243 glXSwapBuffers(re->win->disp, re->win);
246 SDL_GL_SwapBuffers();
251 eng_output_idle_flush(void *data)
253 // Render_Engine *re;
255 // re = (Render_Engine *)data;
259 eng_context_cutout_add(void *data, void *context, int x, int y, int w, int h)
261 // Render_Engine *re;
263 // re = (Render_Engine *)data;
264 // re->gl_context->dc = context;
265 evas_common_draw_context_add_cutout(context, x, y, w, h);
269 eng_context_cutout_clear(void *data, void *context)
271 // Render_Engine *re;
273 // re = (Render_Engine *)data;
274 // re->gl_context->dc = context;
275 evas_common_draw_context_clear_cutouts(context);
279 eng_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h)
283 re = (Render_Engine *)data;
284 evas_gl_common_context_target_surface_set(re->gl_context, surface);
285 re->gl_context->dc = context;
286 evas_gl_common_rect_draw(re->gl_context, x, y, w, h);
290 eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2)
294 re = (Render_Engine *)data;
295 evas_gl_common_context_target_surface_set(re->gl_context, surface);
296 re->gl_context->dc = context;
297 evas_gl_common_line_draw(re->gl_context, x1, y1, x2, y2);
301 eng_polygon_point_add(void *data, void *context __UNUSED__, void *polygon, int x, int y)
305 re = (Render_Engine *)data;
306 return evas_gl_common_poly_point_add(polygon, x, y);
310 eng_polygon_points_clear(void *data, void *context __UNUSED__, void *polygon)
314 re = (Render_Engine *)data;
315 return evas_gl_common_poly_points_clear(polygon);
319 eng_polygon_draw(void *data, void *context, void *surface, void *polygon)
323 re = (Render_Engine *)data;
324 evas_gl_common_context_target_surface_set(re->gl_context, surface);
325 re->gl_context->dc = context;
326 evas_gl_common_poly_draw(re->gl_context, polygon);
330 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__)
332 evas_common_gradient2_color_np_stop_insert(gradient, r, g, b, a, pos);
336 eng_gradient2_clear(void *data __UNUSED__, void *gradient __UNUSED__)
338 evas_common_gradient2_clear(gradient);
342 eng_gradient2_fill_transform_set(void *data __UNUSED__, void *gradient __UNUSED__, void *transform __UNUSED__)
344 evas_common_gradient2_fill_transform_set(gradient, transform);
348 eng_gradient2_fill_spread_set(void *data __UNUSED__, void *gradient __UNUSED__, int spread __UNUSED__)
350 evas_common_gradient2_fill_spread_set(gradient, spread);
354 eng_gradient2_linear_new(void *data __UNUSED__)
356 return evas_common_gradient2_linear_new();
360 eng_gradient2_linear_free(void *data __UNUSED__, void *linear_gradient __UNUSED__)
362 evas_common_gradient2_free(linear_gradient);
366 eng_gradient2_linear_fill_set(void *data __UNUSED__, void *linear_gradient __UNUSED__, float x0 __UNUSED__, float y0 __UNUSED__, float x1 __UNUSED__, float y1 __UNUSED__)
368 evas_common_gradient2_linear_fill_set(linear_gradient, x0, y0, x1, y1);
372 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__)
374 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
375 RGBA_Gradient2 *gr = (RGBA_Gradient2 *)linear_gradient;
377 if (!dc || !gr || !gr->type.geometer) return 0;
378 return !(gr->type.geometer->has_alpha(gr, dc->render_op) |
379 gr->type.geometer->has_mask(gr, dc->render_op));
383 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__)
385 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
387 if (!dc || !linear_gradient) return 0;
392 eng_gradient2_linear_render_pre(void *data __UNUSED__, void *context __UNUSED__, void *linear_gradient __UNUSED__)
394 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
395 RGBA_Gradient2 *gr = (RGBA_Gradient2 *)linear_gradient;
398 if (!dc || !gr || !gr->type.geometer) return;
399 gr->type.geometer->geom_update(gr);
400 len = gr->type.geometer->get_map_len(gr);
401 evas_common_gradient2_map(dc, gr, len);
405 eng_gradient2_linear_render_post(void *data __UNUSED__, void *linear_gradient __UNUSED__)
410 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__)
414 re = (Render_Engine *)data;
415 re->gl_context->dc = context;
419 RGBA_Draw_Context *dc = context;
420 int op = dc->render_op, cuse = dc->clip.use;
422 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
423 im = (RGBA_Image *)evas_cache_image_size_set(&im->cache_entry, w, h);
425 dc->render_op = _EVAS_RENDER_FILL;
428 // draw to buf, copy to tex, draw tex
429 evas_common_gradient2_draw(im, dc, 0, 0, w, h, linear_gradient);
431 gim = evas_gl_common_image_new_from_data(re->gl_context, w, h,
433 EVAS_COLORSPACE_ARGB8888);
436 evas_gl_common_image_draw(re->gl_context, gim, 0, 0, w, h, x, y, w, h, 0);
437 evas_cache_image_drop(&im->cache_entry);
438 evas_gl_common_image_free(gim);
443 eng_gradient2_radial_new(void *data __UNUSED__)
445 return evas_common_gradient2_radial_new();
449 eng_gradient2_radial_free(void *data __UNUSED__, void *radial_gradient __UNUSED__)
451 evas_common_gradient2_free(radial_gradient);
455 eng_gradient2_radial_fill_set(void *data __UNUSED__, void *radial_gradient __UNUSED__, float cx __UNUSED__, float cy __UNUSED__, float rx __UNUSED__, float ry __UNUSED__)
457 evas_common_gradient2_radial_fill_set(radial_gradient, cx, cy, rx, ry);
461 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__)
463 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
464 RGBA_Gradient2 *gr = (RGBA_Gradient2 *)radial_gradient;
466 if (!dc || !gr || !gr->type.geometer) return 0;
467 return !(gr->type.geometer->has_alpha(gr, dc->render_op) |
468 gr->type.geometer->has_mask(gr, dc->render_op));
472 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__)
474 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
476 if (!dc || !radial_gradient) return 0;
481 eng_gradient2_radial_render_pre(void *data __UNUSED__, void *context __UNUSED__, void *radial_gradient __UNUSED__)
483 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
484 RGBA_Gradient2 *gr = (RGBA_Gradient2 *)radial_gradient;
487 if (!dc || !gr || !gr->type.geometer) return;
488 gr->type.geometer->geom_update(gr);
489 len = gr->type.geometer->get_map_len(gr);
490 evas_common_gradient2_map(dc, gr, len);
494 eng_gradient2_radial_render_post(void *data __UNUSED__, void *radial_gradient __UNUSED__)
499 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__)
503 re = (Render_Engine *)data;
504 re->gl_context->dc = context;
508 RGBA_Draw_Context *dc = context;
509 int op = dc->render_op, cuse = dc->clip.use;
511 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
512 im = (RGBA_Image *)evas_cache_image_size_set(&im->cache_entry, w, h);
514 dc->render_op = _EVAS_RENDER_FILL;
517 // draw to buf, copy to tex, draw tex
518 evas_common_gradient2_draw(im, dc, 0, 0, w, h, radial_gradient);
520 gim = evas_gl_common_image_new_from_data(re->gl_context, w, h,
522 EVAS_COLORSPACE_ARGB8888);
525 evas_gl_common_image_draw(re->gl_context, gim, 0, 0, w, h, x, y, w, h, 0);
526 evas_cache_image_drop(&im->cache_entry);
527 evas_gl_common_image_free(gim);
532 eng_gradient_new(void *data __UNUSED__)
534 return evas_common_gradient_new();
538 eng_gradient_free(void *data __UNUSED__, void *gradient)
540 evas_common_gradient_free(gradient);
544 eng_gradient_color_stop_add(void *data __UNUSED__, void *gradient, int r, int g, int b, int a, int delta)
546 evas_common_gradient_color_stop_add(gradient, r, g, b, a, delta);
550 eng_gradient_alpha_stop_add(void *data __UNUSED__, void *gradient, int a, int delta)
552 evas_common_gradient_alpha_stop_add(gradient, a, delta);
556 eng_gradient_color_data_set(void *data __UNUSED__, void *gradient, void *map, int len, int has_alpha)
558 evas_common_gradient_color_data_set(gradient, map, len, has_alpha);
562 eng_gradient_alpha_data_set(void *data __UNUSED__, void *gradient, void *alpha_map, int len)
564 evas_common_gradient_alpha_data_set(gradient, alpha_map, len);
568 eng_gradient_clear(void *data __UNUSED__, void *gradient)
570 evas_common_gradient_clear(gradient);
574 eng_gradient_fill_set(void *data __UNUSED__, void *gradient, int x, int y, int w, int h)
576 evas_common_gradient_fill_set(gradient, x, y, w, h);
580 eng_gradient_fill_angle_set(void *data __UNUSED__, void *gradient, double angle)
582 evas_common_gradient_fill_angle_set(gradient, angle);
586 eng_gradient_fill_spread_set(void *data __UNUSED__, void *gradient, int spread)
588 evas_common_gradient_fill_spread_set(gradient, spread);
592 eng_gradient_angle_set(void *data __UNUSED__, void *gradient, double angle)
594 evas_common_gradient_map_angle_set(gradient, angle);
598 eng_gradient_offset_set(void *data __UNUSED__, void *gradient, float offset)
600 evas_common_gradient_map_offset_set(gradient, offset);
604 eng_gradient_direction_set(void *data __UNUSED__, void *gradient, int direction)
606 evas_common_gradient_map_direction_set(gradient, direction);
610 eng_gradient_type_set(void *data __UNUSED__, void *gradient, char *name, char *params)
612 evas_common_gradient_type_set(gradient, name, params);
616 eng_gradient_is_opaque(void *data, void *context, void *gradient, int x, int y, int w, int h)
618 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
619 RGBA_Gradient *gr = (RGBA_Gradient *)gradient;
621 if (!dc || !gr || !gr->type.geometer) return 0;
622 return !(gr->type.geometer->has_alpha(gr, dc->render_op) |
623 gr->type.geometer->has_mask(gr, dc->render_op));
627 eng_gradient_is_visible(void *data, void *context, void *gradient, int x, int y, int w, int h)
629 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
631 if (!dc || !gradient) return 0;
636 eng_gradient_render_pre(void *data, void *context, void *gradient)
638 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
639 RGBA_Gradient *gr = (RGBA_Gradient *)gradient;
642 if (!dc || !gr || !gr->type.geometer) return;
643 gr->type.geometer->geom_set(gr);
644 len = gr->type.geometer->get_map_len(gr);
645 evas_common_gradient_map(dc, gr, len);
649 eng_gradient_render_post(void *data __UNUSED__, void *gradient)
654 eng_gradient_draw(void *data, void *context, void *surface __UNUSED__, void *gradient, int x, int y, int w, int h)
658 re = (Render_Engine *)data;
659 re->gl_context->dc = context;
663 RGBA_Draw_Context *dc = context;
664 int op = dc->render_op, cuse = dc->clip.use;
666 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
667 im = (RGBA_Image *)evas_cache_image_size_set(&im->cache_entry, w, h);
669 dc->render_op = _EVAS_RENDER_FILL;
672 // draw to buf, copy to tex, draw tex
673 evas_common_gradient_draw(im, dc, 0, 0, w, h, gradient);
675 gim = evas_gl_common_image_new_from_data(re->gl_context, w, h,
677 EVAS_COLORSPACE_ARGB8888);
680 evas_gl_common_image_draw(re->gl_context, gim, 0, 0, w, h, x, y, w, h, 0);
681 evas_cache_image_drop(&im->cache_entry);
682 evas_gl_common_image_free(gim);
687 eng_image_alpha_get(void *data, void *image)
689 // Render_Engine *re;
692 // re = (Render_Engine *)data;
693 if (!image) return 1;
699 eng_image_colorspace_get(void *data, void *image)
701 // Render_Engine *re;
704 // re = (Render_Engine *)data;
705 if (!image) return EVAS_COLORSPACE_ARGB8888;
711 eng_image_alpha_set(void *data, void *image, int has_alpha)
716 re = (Render_Engine *)data;
717 if (!image) return NULL;
721 im->alpha = has_alpha;
724 /* FIXME: can move to gl_common */
725 if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im;
726 if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image;
727 else if ((!has_alpha) && (!im->im->cache_entry.flags.alpha)) return image;
728 if (im->references > 1)
730 Evas_GL_Image *im_new;
732 im_new = evas_gl_common_image_new_from_copied_data(im->gc, im->im->cache_entry.w, im->im->cache_entry.h, im->im->image.data,
733 eng_image_alpha_get(data, image),
734 eng_image_colorspace_get(data, image));
735 if (!im_new) return im;
736 evas_gl_common_image_free(im);
740 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
741 im->im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
746 eng_image_border_set(void *data, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
748 // Render_Engine *re;
750 // re = (Render_Engine *)data;
755 eng_image_border_get(void *data, void *image __UNUSED__, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
757 // Render_Engine *re;
759 // re = (Render_Engine *)data;
763 eng_image_comment_get(void *data, void *image, char *key __UNUSED__)
765 // Render_Engine *re;
768 // re = (Render_Engine *)data;
769 if (!image) return NULL;
771 if (!im->im) return NULL;
772 return im->im->info.comment;
776 eng_image_format_get(void *data, void *image)
778 // Render_Engine *re;
781 // re = (Render_Engine *)data;
787 eng_image_colorspace_set(void *data, void *image, int cspace)
792 re = (Render_Engine *)data;
795 if (im->native.data) return;
796 /* FIXME: can move to gl_common */
797 if (im->cs.space == cspace) return;
798 evas_cache_image_colorspace(&im->im->cache_entry, cspace);
801 case EVAS_COLORSPACE_ARGB8888:
804 if (!im->cs.no_free) free(im->cs.data);
809 case EVAS_COLORSPACE_YCBCR422P601_PL:
810 case EVAS_COLORSPACE_YCBCR422P709_PL:
811 if (im->tex) evas_gl_common_texture_free(im->tex);
815 if (!im->cs.no_free) free(im->cs.data);
817 im->cs.data = calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
824 im->cs.space = cspace;
827 /////////////////////////////////////////////////////////////////////////
830 typedef struct _Native Native;
834 Evas_Native_Surface ns;
836 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
837 EGLSurface egl_surface;
842 _native_bind_cb(void *data, void *image)
847 _native_unbind_cb(void *data, void *image)
852 _native_free_cb(void *data, void *image)
857 eng_image_native_set(void *data, void *image, void *native)
862 eng_image_native_get(void *data, void *image)
869 /////////////////////////////////////////////////////////////////////////
872 eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
876 re = (Render_Engine *)data;
877 *error = EVAS_LOAD_ERROR_NONE;
878 return evas_gl_common_image_load(re->gl_context, file, key, lo, error);
882 eng_image_new_from_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
886 re = (Render_Engine *)data;
887 return evas_gl_common_image_new_from_data(re->gl_context, w, h, image_data, alpha, cspace);
891 eng_image_new_from_copied_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
895 re = (Render_Engine *)data;
896 return evas_gl_common_image_new_from_copied_data(re->gl_context, w, h, image_data, alpha, cspace);
900 eng_image_free(void *data, void *image)
904 re = (Render_Engine *)data;
906 evas_gl_common_image_free(image);
910 eng_image_size_get(void *data, void *image, int *w, int *h)
912 // Render_Engine *re;
914 // re = (Render_Engine *)data;
921 if (w) *w = ((Evas_GL_Image *)image)->w;
922 if (h) *h = ((Evas_GL_Image *)image)->h;
926 eng_image_size_set(void *data, void *image, int w, int h)
929 Evas_GL_Image *im = image;
930 Evas_GL_Image *im_old;
932 re = (Render_Engine *)data;
933 if (!im) return NULL;
941 if ((eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P601_PL) ||
942 (eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P709_PL))
944 if ((im_old) && (im_old->im->cache_entry.w == w) && (im_old->im->cache_entry.h == h))
948 im = evas_gl_common_image_new(re->gl_context, w, h,
949 eng_image_alpha_get(data, image),
950 eng_image_colorspace_get(data, image));
952 evas_common_load_image_data_from_file(im_old->im);
953 if (im_old->im->image->data)
955 evas_common_blit_rectangle(im_old->im, im->im, 0, 0, w, h, 0, 0);
956 evas_common_cpu_end_opt();
959 evas_gl_common_image_free(im_old);
962 im = evas_gl_common_image_new(re->gl_context, w, h, 1, EVAS_COLORSPACE_ARGB8888);
967 eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
970 Evas_GL_Image *im = image;
972 re = (Render_Engine *)data;
973 if (!image) return NULL;
974 if (im->native.data) return image;
975 evas_gl_common_image_dirty(image, x, y, w, h);
980 eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data)
985 re = (Render_Engine *)data;
997 evas_cache_image_load_data(&im->im->cache_entry);
998 switch (im->cs.space)
1000 case EVAS_COLORSPACE_ARGB8888:
1003 if (im->references > 1)
1005 Evas_GL_Image *im_new;
1007 im_new = evas_gl_common_image_new_from_copied_data(im->gc, im->im->cache_entry.w, im->im->cache_entry.h, im->im->image.data,
1008 eng_image_alpha_get(data, image),
1009 eng_image_colorspace_get(data, image));
1015 evas_gl_common_image_free(im);
1019 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
1021 *image_data = im->im->image.data;
1023 case EVAS_COLORSPACE_YCBCR422P601_PL:
1024 case EVAS_COLORSPACE_YCBCR422P709_PL:
1025 *image_data = im->cs.data;
1035 eng_image_data_put(void *data, void *image, DATA32 *image_data)
1038 Evas_GL_Image *im, *im2;
1040 re = (Render_Engine *)data;
1041 if (!image) return NULL;
1043 if (im->native.data) return image;
1044 switch (im->cs.space)
1046 case EVAS_COLORSPACE_ARGB8888:
1047 if (image_data != im->im->image.data)
1051 w = im->im->cache_entry.w;
1052 h = im->im->cache_entry.h;
1053 im2 = eng_image_new_from_data(data, w, h, image_data,
1054 eng_image_alpha_get(data, image),
1055 eng_image_colorspace_get(data, image));
1056 if (!im2) return im;
1057 evas_gl_common_image_free(im);
1061 case EVAS_COLORSPACE_YCBCR422P601_PL:
1062 case EVAS_COLORSPACE_YCBCR422P709_PL:
1063 if (image_data != im->cs.data)
1067 if (!im->cs.no_free) free(im->cs.data);
1069 im->cs.data = image_data;
1076 /* hmmm - but if we wrote... why bother? */
1077 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
1082 eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
1084 Evas_GL_Image *gim = image;
1088 if (gim->native.data) return;
1089 im = (RGBA_Image *)gim->im;
1091 evas_cache_image_preload_data(&im->cache_entry, target);
1095 eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
1097 Evas_GL_Image *gim = image;
1101 if (gim->native.data) return;
1102 im = (RGBA_Image *)gim->im;
1104 evas_cache_image_preload_cancel(&im->cache_entry, target);
1108 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)
1112 re = (Render_Engine *)data;
1114 evas_gl_common_context_target_surface_set(re->gl_context, surface);
1115 re->gl_context->dc = context;
1116 evas_gl_common_image_draw(re->gl_context, image,
1117 src_x, src_y, src_w, src_h,
1118 dst_x, dst_y, dst_w, dst_h,
1123 eng_image_scale_hint_set(void *data __UNUSED__, void *image, int hint)
1128 eng_image_map4_draw(void *data __UNUSED__, void *context, void *surface, void *image, RGBA_Map_Point *p, int smooth, int level)
1132 re = (Render_Engine *)data;
1133 evas_gl_common_context_target_surface_set(re->gl_context, surface);
1134 re->gl_context->dc = context;
1135 evas_gl_common_image_map4_draw(re->gl_context, image, p, smooth, level);
1139 eng_image_map_surface_new(void *data __UNUSED__, int w, int h, int alpha)
1143 re = (Render_Engine *)data;
1144 return evas_gl_common_image_surface_new(re->gl_context, w, h, alpha);
1148 eng_image_map_surface_free(void *data __UNUSED__, void *surface)
1150 evas_gl_common_image_free(surface);
1154 eng_image_scale_hint_get(void *data __UNUSED__, void *image)
1156 return EVAS_IMAGE_SCALE_HINT_NONE;
1160 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 char *text)
1164 re = (Render_Engine *)data;
1165 evas_gl_common_context_target_surface_set(re->gl_context, surface);
1166 re->gl_context->dc = context;
1168 // FIXME: put im into context so we can free it
1169 static RGBA_Image *im = NULL;
1172 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
1173 im->cache_entry.w = re->w;
1174 im->cache_entry.h = re->h;
1175 evas_common_draw_context_font_ext_set(context,
1177 evas_gl_font_texture_new,
1178 evas_gl_font_texture_free,
1179 evas_gl_font_texture_draw);
1180 evas_common_font_draw(im, context, font, x, y, text);
1181 evas_common_draw_context_font_ext_set(context,
1190 eng_canvas_alpha_get(void *data __UNUSED__, void *info __UNUSED__)
1192 // FIXME: support ARGB gl targets!!!
1197 module_open(Evas_Module *em)
1200 /* get whatever engine module we inherit from */
1201 if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
1202 if (_evas_engine_GL_SDL_log_dom < 0)
1203 _evas_engine_GL_SDL_log_dom = eina_log_domain_register("EvasEngineGLSDL", EVAS_DEFAULT_LOG_COLOR);
1204 if (_evas_engine_GL_SDL_log_dom < 0)
1206 EINA_LOG_ERR("Impossible to create a log domain for GL SDL engine.\n");
1209 /* store it for later use */
1211 /* now to override methods */
1212 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
1216 ORD(canvas_alpha_get);
1219 ORD(output_tile_size_set);
1220 ORD(output_redraws_rect_add);
1221 ORD(output_redraws_rect_del);
1222 ORD(output_redraws_clear);
1223 ORD(output_redraws_next_update_get);
1224 ORD(output_redraws_next_update_push);
1225 ORD(context_cutout_add);
1226 ORD(context_cutout_clear);
1228 ORD(output_idle_flush);
1229 ORD(rectangle_draw);
1231 ORD(polygon_point_add);
1232 ORD(polygon_points_clear);
1235 ORD(gradient2_color_np_stop_insert);
1236 ORD(gradient2_clear);
1237 ORD(gradient2_fill_transform_set);
1238 ORD(gradient2_fill_spread_set);
1239 ORD(gradient2_linear_new);
1240 ORD(gradient2_linear_free);
1241 ORD(gradient2_linear_fill_set);
1242 ORD(gradient2_linear_is_opaque);
1243 ORD(gradient2_linear_is_visible);
1244 ORD(gradient2_linear_render_pre);
1245 ORD(gradient2_linear_render_post);
1246 ORD(gradient2_linear_draw);
1247 ORD(gradient2_radial_new);
1248 ORD(gradient2_radial_free);
1249 ORD(gradient2_radial_fill_set);
1250 ORD(gradient2_radial_is_opaque);
1251 ORD(gradient2_radial_is_visible);
1252 ORD(gradient2_radial_render_pre);
1253 ORD(gradient2_radial_render_post);
1254 ORD(gradient2_radial_draw);
1258 ORD(gradient_color_stop_add);
1259 ORD(gradient_alpha_stop_add);
1260 ORD(gradient_color_data_set);
1261 ORD(gradient_alpha_data_set);
1262 ORD(gradient_clear);
1263 ORD(gradient_fill_set);
1264 ORD(gradient_fill_angle_set);
1265 ORD(gradient_fill_spread_set);
1266 ORD(gradient_angle_set);
1267 ORD(gradient_offset_set);
1268 ORD(gradient_direction_set);
1269 ORD(gradient_type_set);
1270 ORD(gradient_is_opaque);
1271 ORD(gradient_is_visible);
1272 ORD(gradient_render_pre);
1273 ORD(gradient_render_post);
1276 ORD(image_new_from_data);
1277 ORD(image_new_from_copied_data);
1279 ORD(image_size_get);
1280 ORD(image_size_set);
1281 ORD(image_dirty_region);
1282 ORD(image_data_get);
1283 ORD(image_data_put);
1284 ORD(image_data_preload_request);
1285 ORD(image_data_preload_cancel);
1286 ORD(image_alpha_set);
1287 ORD(image_alpha_get);
1288 ORD(image_border_set);
1289 ORD(image_border_get);
1291 ORD(image_comment_get);
1292 ORD(image_format_get);
1293 ORD(image_colorspace_set);
1294 ORD(image_colorspace_get);
1295 ORD(image_native_set);
1296 ORD(image_native_get);
1299 ORD(image_scale_hint_set);
1300 ORD(image_scale_hint_get);
1302 ORD(image_map4_draw);
1303 ORD(image_map_surface_new);
1304 ORD(image_map_surface_free);
1306 /* now advertise out own api */
1307 em->functions = (void *)(&func);
1312 module_close(Evas_Module *em)
1314 eina_log_domain_unregister(_evas_engine_GL_SDL_log_dom);
1317 static Evas_Module_Api evas_modapi =
1319 EVAS_MODULE_API_VERSION,
1328 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, gl_sdl);
1330 #ifndef EVAS_STATIC_BUILD_GL_SDL
1331 EVAS_EINA_MODULE_DEFINE(engine, gl_sdl);
1335 _sdl_output_setup (int w, int h, int fullscreen, int noframe)
1337 Render_Engine *re = calloc(1, sizeof(Render_Engine));
1338 SDL_Surface *surface;
1339 int context_attrs[3];
1340 int config_attrs[20];
1341 int major_version, minor_version;
1344 /* if we haven't initialized - init (automatic abort if already done) */
1345 evas_common_cpu_init();
1346 evas_common_blend_init();
1347 evas_common_image_init();
1348 evas_common_convert_init();
1349 evas_common_scale_init();
1350 evas_common_rectangle_init();
1351 evas_common_gradient_init();
1352 evas_common_polygon_init();
1353 evas_common_line_init();
1354 evas_common_font_init();
1355 evas_common_draw_init();
1356 evas_common_tilebuf_init();
1358 if (w <= 0) w = 640;
1359 if (h <= 0) h = 480;
1361 /* GL Initialization */
1362 #ifdef HAVE_SDL_GL_CONTEXT_VERSION
1363 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
1364 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
1366 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
1367 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
1368 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
1369 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
1370 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
1371 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
1373 surface = SDL_SetVideoMode(w, h, 32, EVAS_SDL_GL_FLAG
1374 | (fullscreen ? SDL_FULLSCREEN : 0)
1375 | (noframe ? SDL_NOFRAME : 0));
1379 CRIT("SDL_SetVideoMode [ %i x %i x 32 ] failed.", w, h);
1383 re->gl_context = evas_gl_common_context_new();
1384 if (!re->gl_context)
1389 evas_gl_common_context_use(re->gl_context);
1390 evas_gl_common_context_resize(re->gl_context, w, h);
1392 /* End GL Initialization */