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 if(SDL_GetVideoSurface()->flags & SDL_RESIZABLE)
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));
94 ERR("Unable to change the resolution to : %ix%i", w, h);
100 evas_gl_common_context_resize(re->gl_context, w, h);
104 eng_output_tile_size_set(void *data, int w __UNUSED__, int h __UNUSED__)
106 // Render_Engine *re;
108 // re = (Render_Engine *)data;
112 eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
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)
124 re->draw.x2 = x + w - 1;
125 re->draw.y2 = y + h - 1;
129 re->draw.x2 = re->w - 1;
130 re->draw.y2 = re->h - 1;
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;
144 eng_output_redraws_rect_del(void *data, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
146 // Render_Engine *re;
148 // re = (Render_Engine *)data;
152 eng_output_redraws_clear(void *data)
156 re = (Render_Engine *)data;
158 // INF("GL: finish update cycle!");
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.)
167 #define SLOW_GL_COPY_RECT 1
168 /* vsync games - not for now though */
169 //#define VSYNC_TO_SCREEN 1
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)
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)
181 // printf("GL: NO updates!\n");
184 // printf("GL: update....!\n");
185 #ifdef SLOW_GL_COPY_RECT
186 /* if any update - just return the whole canvas - works with swap
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
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;
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;
220 eng_output_redraws_next_update_push(void *data, void *surface __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
224 re = (Render_Engine *)data;
225 /* put back update surface.. in this case just unflag redraw */
228 evas_gl_common_context_flush(re->gl_context);
229 //x// printf("frame -> push\n");
233 eng_output_flush(void *data)
237 re = (Render_Engine *)data;
238 if (!re->draw.drew) return;
239 //x// printf("frame -> flush\n");
243 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
245 eglSwapBuffers(re->egl_disp, re->egl_surface[0]);
247 glXSwapBuffers(re->win->disp, re->win);
250 SDL_GL_SwapBuffers();
255 eng_output_idle_flush(void *data)
257 // Render_Engine *re;
259 // re = (Render_Engine *)data;
263 eng_context_cutout_add(void *data, void *context, int x, int y, int w, int h)
265 // Render_Engine *re;
267 // re = (Render_Engine *)data;
268 // re->gl_context->dc = context;
269 evas_common_draw_context_add_cutout(context, x, y, w, h);
273 eng_context_cutout_clear(void *data, void *context)
275 // Render_Engine *re;
277 // re = (Render_Engine *)data;
278 // re->gl_context->dc = context;
279 evas_common_draw_context_clear_cutouts(context);
283 eng_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h)
287 re = (Render_Engine *)data;
288 evas_gl_common_context_target_surface_set(re->gl_context, surface);
289 re->gl_context->dc = context;
290 evas_gl_common_rect_draw(re->gl_context, x, y, w, h);
294 eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2)
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_line_draw(re->gl_context, x1, y1, x2, y2);
305 eng_polygon_point_add(void *data, void *context __UNUSED__, void *polygon, int x, int y)
309 re = (Render_Engine *)data;
310 return evas_gl_common_poly_point_add(polygon, x, y);
314 eng_polygon_points_clear(void *data, void *context __UNUSED__, void *polygon)
318 re = (Render_Engine *)data;
319 return evas_gl_common_poly_points_clear(polygon);
323 eng_polygon_draw(void *data, void *context, void *surface, void *polygon)
327 re = (Render_Engine *)data;
328 evas_gl_common_context_target_surface_set(re->gl_context, surface);
329 re->gl_context->dc = context;
330 evas_gl_common_poly_draw(re->gl_context, polygon);
334 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__)
336 evas_common_gradient2_color_np_stop_insert(gradient, r, g, b, a, pos);
340 eng_gradient2_clear(void *data __UNUSED__, void *gradient __UNUSED__)
342 evas_common_gradient2_clear(gradient);
346 eng_gradient2_fill_transform_set(void *data __UNUSED__, void *gradient __UNUSED__, void *transform __UNUSED__)
348 evas_common_gradient2_fill_transform_set(gradient, transform);
352 eng_gradient2_fill_spread_set(void *data __UNUSED__, void *gradient __UNUSED__, int spread __UNUSED__)
354 evas_common_gradient2_fill_spread_set(gradient, spread);
358 eng_gradient2_linear_new(void *data __UNUSED__)
360 return evas_common_gradient2_linear_new();
364 eng_gradient2_linear_free(void *data __UNUSED__, void *linear_gradient __UNUSED__)
366 evas_common_gradient2_free(linear_gradient);
370 eng_gradient2_linear_fill_set(void *data __UNUSED__, void *linear_gradient __UNUSED__, float x0 __UNUSED__, float y0 __UNUSED__, float x1 __UNUSED__, float y1 __UNUSED__)
372 evas_common_gradient2_linear_fill_set(linear_gradient, x0, y0, x1, y1);
376 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__)
378 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
379 RGBA_Gradient2 *gr = (RGBA_Gradient2 *)linear_gradient;
381 if (!dc || !gr || !gr->type.geometer) return 0;
382 return !(gr->type.geometer->has_alpha(gr, dc->render_op) |
383 gr->type.geometer->has_mask(gr, dc->render_op));
387 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__)
389 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
391 if (!dc || !linear_gradient) return 0;
396 eng_gradient2_linear_render_pre(void *data __UNUSED__, void *context __UNUSED__, void *linear_gradient __UNUSED__)
398 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
399 RGBA_Gradient2 *gr = (RGBA_Gradient2 *)linear_gradient;
402 if (!dc || !gr || !gr->type.geometer) return;
403 gr->type.geometer->geom_update(gr);
404 len = gr->type.geometer->get_map_len(gr);
405 evas_common_gradient2_map(dc, gr, len);
409 eng_gradient2_linear_render_post(void *data __UNUSED__, void *linear_gradient __UNUSED__)
414 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__)
418 re = (Render_Engine *)data;
419 re->gl_context->dc = context;
423 RGBA_Draw_Context *dc = context;
424 int op = dc->render_op, cuse = dc->clip.use;
426 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
427 im = (RGBA_Image *)evas_cache_image_size_set(&im->cache_entry, w, h);
429 dc->render_op = _EVAS_RENDER_FILL;
432 // draw to buf, copy to tex, draw tex
433 evas_common_gradient2_draw(im, dc, 0, 0, w, h, linear_gradient);
435 gim = evas_gl_common_image_new_from_data(re->gl_context, w, h,
437 EVAS_COLORSPACE_ARGB8888);
440 evas_gl_common_image_draw(re->gl_context, gim, 0, 0, w, h, x, y, w, h, 0);
441 evas_cache_image_drop(&im->cache_entry);
442 evas_gl_common_image_free(gim);
447 eng_gradient2_radial_new(void *data __UNUSED__)
449 return evas_common_gradient2_radial_new();
453 eng_gradient2_radial_free(void *data __UNUSED__, void *radial_gradient __UNUSED__)
455 evas_common_gradient2_free(radial_gradient);
459 eng_gradient2_radial_fill_set(void *data __UNUSED__, void *radial_gradient __UNUSED__, float cx __UNUSED__, float cy __UNUSED__, float rx __UNUSED__, float ry __UNUSED__)
461 evas_common_gradient2_radial_fill_set(radial_gradient, cx, cy, rx, ry);
465 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__)
467 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
468 RGBA_Gradient2 *gr = (RGBA_Gradient2 *)radial_gradient;
470 if (!dc || !gr || !gr->type.geometer) return 0;
471 return !(gr->type.geometer->has_alpha(gr, dc->render_op) |
472 gr->type.geometer->has_mask(gr, dc->render_op));
476 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__)
478 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
480 if (!dc || !radial_gradient) return 0;
485 eng_gradient2_radial_render_pre(void *data __UNUSED__, void *context __UNUSED__, void *radial_gradient __UNUSED__)
487 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
488 RGBA_Gradient2 *gr = (RGBA_Gradient2 *)radial_gradient;
491 if (!dc || !gr || !gr->type.geometer) return;
492 gr->type.geometer->geom_update(gr);
493 len = gr->type.geometer->get_map_len(gr);
494 evas_common_gradient2_map(dc, gr, len);
498 eng_gradient2_radial_render_post(void *data __UNUSED__, void *radial_gradient __UNUSED__)
503 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__)
507 re = (Render_Engine *)data;
508 re->gl_context->dc = context;
512 RGBA_Draw_Context *dc = context;
513 int op = dc->render_op, cuse = dc->clip.use;
515 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
516 im = (RGBA_Image *)evas_cache_image_size_set(&im->cache_entry, w, h);
518 dc->render_op = _EVAS_RENDER_FILL;
521 // draw to buf, copy to tex, draw tex
522 evas_common_gradient2_draw(im, dc, 0, 0, w, h, radial_gradient);
524 gim = evas_gl_common_image_new_from_data(re->gl_context, w, h,
526 EVAS_COLORSPACE_ARGB8888);
529 evas_gl_common_image_draw(re->gl_context, gim, 0, 0, w, h, x, y, w, h, 0);
530 evas_cache_image_drop(&im->cache_entry);
531 evas_gl_common_image_free(gim);
536 eng_gradient_new(void *data __UNUSED__)
538 return evas_common_gradient_new();
542 eng_gradient_free(void *data __UNUSED__, void *gradient)
544 evas_common_gradient_free(gradient);
548 eng_gradient_color_stop_add(void *data __UNUSED__, void *gradient, int r, int g, int b, int a, int delta)
550 evas_common_gradient_color_stop_add(gradient, r, g, b, a, delta);
554 eng_gradient_alpha_stop_add(void *data __UNUSED__, void *gradient, int a, int delta)
556 evas_common_gradient_alpha_stop_add(gradient, a, delta);
560 eng_gradient_color_data_set(void *data __UNUSED__, void *gradient, void *map, int len, int has_alpha)
562 evas_common_gradient_color_data_set(gradient, map, len, has_alpha);
566 eng_gradient_alpha_data_set(void *data __UNUSED__, void *gradient, void *alpha_map, int len)
568 evas_common_gradient_alpha_data_set(gradient, alpha_map, len);
572 eng_gradient_clear(void *data __UNUSED__, void *gradient)
574 evas_common_gradient_clear(gradient);
578 eng_gradient_fill_set(void *data __UNUSED__, void *gradient, int x, int y, int w, int h)
580 evas_common_gradient_fill_set(gradient, x, y, w, h);
584 eng_gradient_fill_angle_set(void *data __UNUSED__, void *gradient, double angle)
586 evas_common_gradient_fill_angle_set(gradient, angle);
590 eng_gradient_fill_spread_set(void *data __UNUSED__, void *gradient, int spread)
592 evas_common_gradient_fill_spread_set(gradient, spread);
596 eng_gradient_angle_set(void *data __UNUSED__, void *gradient, double angle)
598 evas_common_gradient_map_angle_set(gradient, angle);
602 eng_gradient_offset_set(void *data __UNUSED__, void *gradient, float offset)
604 evas_common_gradient_map_offset_set(gradient, offset);
608 eng_gradient_direction_set(void *data __UNUSED__, void *gradient, int direction)
610 evas_common_gradient_map_direction_set(gradient, direction);
614 eng_gradient_type_set(void *data __UNUSED__, void *gradient, char *name, char *params)
616 evas_common_gradient_type_set(gradient, name, params);
620 eng_gradient_is_opaque(void *data, void *context, void *gradient, int x, int y, int w, int h)
622 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
623 RGBA_Gradient *gr = (RGBA_Gradient *)gradient;
625 if (!dc || !gr || !gr->type.geometer) return 0;
626 return !(gr->type.geometer->has_alpha(gr, dc->render_op) |
627 gr->type.geometer->has_mask(gr, dc->render_op));
631 eng_gradient_is_visible(void *data, void *context, void *gradient, int x, int y, int w, int h)
633 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
635 if (!dc || !gradient) return 0;
640 eng_gradient_render_pre(void *data, void *context, void *gradient)
642 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
643 RGBA_Gradient *gr = (RGBA_Gradient *)gradient;
646 if (!dc || !gr || !gr->type.geometer) return;
647 gr->type.geometer->geom_set(gr);
648 len = gr->type.geometer->get_map_len(gr);
649 evas_common_gradient_map(dc, gr, len);
653 eng_gradient_render_post(void *data __UNUSED__, void *gradient)
658 eng_gradient_draw(void *data, void *context, void *surface __UNUSED__, void *gradient, int x, int y, int w, int h)
662 re = (Render_Engine *)data;
663 re->gl_context->dc = context;
667 RGBA_Draw_Context *dc = context;
668 int op = dc->render_op, cuse = dc->clip.use;
670 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
671 im = (RGBA_Image *)evas_cache_image_size_set(&im->cache_entry, w, h);
673 dc->render_op = _EVAS_RENDER_FILL;
676 // draw to buf, copy to tex, draw tex
677 evas_common_gradient_draw(im, dc, 0, 0, w, h, gradient);
679 gim = evas_gl_common_image_new_from_data(re->gl_context, w, h,
681 EVAS_COLORSPACE_ARGB8888);
684 evas_gl_common_image_draw(re->gl_context, gim, 0, 0, w, h, x, y, w, h, 0);
685 evas_cache_image_drop(&im->cache_entry);
686 evas_gl_common_image_free(gim);
691 eng_image_alpha_get(void *data, void *image)
693 // Render_Engine *re;
696 // re = (Render_Engine *)data;
697 if (!image) return 1;
703 eng_image_colorspace_get(void *data, void *image)
705 // Render_Engine *re;
708 // re = (Render_Engine *)data;
709 if (!image) return EVAS_COLORSPACE_ARGB8888;
715 eng_image_alpha_set(void *data, void *image, int has_alpha)
720 re = (Render_Engine *)data;
721 if (!image) return NULL;
725 im->alpha = has_alpha;
728 /* FIXME: can move to gl_common */
729 if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im;
730 if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image;
731 else if ((!has_alpha) && (!im->im->cache_entry.flags.alpha)) return image;
732 if (im->references > 1)
734 Evas_GL_Image *im_new;
736 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,
737 eng_image_alpha_get(data, image),
738 eng_image_colorspace_get(data, image));
739 if (!im_new) return im;
740 evas_gl_common_image_free(im);
744 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
745 im->im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
750 eng_image_border_set(void *data, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
752 // Render_Engine *re;
754 // re = (Render_Engine *)data;
759 eng_image_border_get(void *data, void *image __UNUSED__, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
761 // Render_Engine *re;
763 // re = (Render_Engine *)data;
767 eng_image_comment_get(void *data, void *image, char *key __UNUSED__)
769 // Render_Engine *re;
772 // re = (Render_Engine *)data;
773 if (!image) return NULL;
775 if (!im->im) return NULL;
776 return im->im->info.comment;
780 eng_image_format_get(void *data, void *image)
782 // Render_Engine *re;
785 // re = (Render_Engine *)data;
791 eng_image_colorspace_set(void *data, void *image, int cspace)
796 re = (Render_Engine *)data;
799 if (im->native.data) return;
800 /* FIXME: can move to gl_common */
801 if (im->cs.space == cspace) return;
802 evas_cache_image_colorspace(&im->im->cache_entry, cspace);
805 case EVAS_COLORSPACE_ARGB8888:
808 if (!im->cs.no_free) free(im->cs.data);
813 case EVAS_COLORSPACE_YCBCR422P601_PL:
814 case EVAS_COLORSPACE_YCBCR422P709_PL:
815 if (im->tex) evas_gl_common_texture_free(im->tex);
819 if (!im->cs.no_free) free(im->cs.data);
821 im->cs.data = calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
828 im->cs.space = cspace;
831 /////////////////////////////////////////////////////////////////////////
834 typedef struct _Native Native;
838 Evas_Native_Surface ns;
840 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
841 EGLSurface egl_surface;
846 _native_bind_cb(void *data, void *image)
851 _native_unbind_cb(void *data, void *image)
856 _native_free_cb(void *data, void *image)
861 eng_image_native_set(void *data, void *image, void *native)
866 eng_image_native_get(void *data, void *image)
873 /////////////////////////////////////////////////////////////////////////
876 eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
880 re = (Render_Engine *)data;
881 *error = EVAS_LOAD_ERROR_NONE;
882 return evas_gl_common_image_load(re->gl_context, file, key, lo, error);
886 eng_image_new_from_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
890 re = (Render_Engine *)data;
891 return evas_gl_common_image_new_from_data(re->gl_context, w, h, image_data, alpha, cspace);
895 eng_image_new_from_copied_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
899 re = (Render_Engine *)data;
900 return evas_gl_common_image_new_from_copied_data(re->gl_context, w, h, image_data, alpha, cspace);
904 eng_image_free(void *data, void *image)
908 re = (Render_Engine *)data;
910 evas_gl_common_image_free(image);
914 eng_image_size_get(void *data, void *image, int *w, int *h)
916 // Render_Engine *re;
918 // re = (Render_Engine *)data;
925 if (w) *w = ((Evas_GL_Image *)image)->w;
926 if (h) *h = ((Evas_GL_Image *)image)->h;
930 eng_image_size_set(void *data, void *image, int w, int h)
933 Evas_GL_Image *im = image;
934 Evas_GL_Image *im_old;
936 re = (Render_Engine *)data;
937 if (!im) return NULL;
945 if ((eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P601_PL) ||
946 (eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P709_PL))
948 if ((im_old) && (im_old->im->cache_entry.w == w) && (im_old->im->cache_entry.h == h))
952 im = evas_gl_common_image_new(re->gl_context, w, h,
953 eng_image_alpha_get(data, image),
954 eng_image_colorspace_get(data, image));
956 evas_common_load_image_data_from_file(im_old->im);
957 if (im_old->im->image->data)
959 evas_common_blit_rectangle(im_old->im, im->im, 0, 0, w, h, 0, 0);
960 evas_common_cpu_end_opt();
963 evas_gl_common_image_free(im_old);
966 im = evas_gl_common_image_new(re->gl_context, w, h, 1, EVAS_COLORSPACE_ARGB8888);
971 eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
974 Evas_GL_Image *im = image;
976 re = (Render_Engine *)data;
977 if (!image) return NULL;
978 if (im->native.data) return image;
979 evas_gl_common_image_dirty(image, x, y, w, h);
984 eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data)
989 re = (Render_Engine *)data;
1001 evas_cache_image_load_data(&im->im->cache_entry);
1002 switch (im->cs.space)
1004 case EVAS_COLORSPACE_ARGB8888:
1007 if (im->references > 1)
1009 Evas_GL_Image *im_new;
1011 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,
1012 eng_image_alpha_get(data, image),
1013 eng_image_colorspace_get(data, image));
1019 evas_gl_common_image_free(im);
1023 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
1025 *image_data = im->im->image.data;
1027 case EVAS_COLORSPACE_YCBCR422P601_PL:
1028 case EVAS_COLORSPACE_YCBCR422P709_PL:
1029 *image_data = im->cs.data;
1039 eng_image_data_put(void *data, void *image, DATA32 *image_data)
1042 Evas_GL_Image *im, *im2;
1044 re = (Render_Engine *)data;
1045 if (!image) return NULL;
1047 if (im->native.data) return image;
1048 switch (im->cs.space)
1050 case EVAS_COLORSPACE_ARGB8888:
1051 if (image_data != im->im->image.data)
1055 w = im->im->cache_entry.w;
1056 h = im->im->cache_entry.h;
1057 im2 = eng_image_new_from_data(data, w, h, image_data,
1058 eng_image_alpha_get(data, image),
1059 eng_image_colorspace_get(data, image));
1060 if (!im2) return im;
1061 evas_gl_common_image_free(im);
1065 case EVAS_COLORSPACE_YCBCR422P601_PL:
1066 case EVAS_COLORSPACE_YCBCR422P709_PL:
1067 if (image_data != im->cs.data)
1071 if (!im->cs.no_free) free(im->cs.data);
1073 im->cs.data = image_data;
1080 /* hmmm - but if we wrote... why bother? */
1081 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
1086 eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
1088 Evas_GL_Image *gim = image;
1092 if (gim->native.data) return;
1093 im = (RGBA_Image *)gim->im;
1095 evas_cache_image_preload_data(&im->cache_entry, target);
1099 eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
1101 Evas_GL_Image *gim = image;
1105 if (gim->native.data) return;
1106 im = (RGBA_Image *)gim->im;
1108 evas_cache_image_preload_cancel(&im->cache_entry, target);
1112 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)
1116 re = (Render_Engine *)data;
1118 evas_gl_common_context_target_surface_set(re->gl_context, surface);
1119 re->gl_context->dc = context;
1120 evas_gl_common_image_draw(re->gl_context, image,
1121 src_x, src_y, src_w, src_h,
1122 dst_x, dst_y, dst_w, dst_h,
1127 eng_image_scale_hint_set(void *data __UNUSED__, void *image, int hint)
1132 eng_image_map4_draw(void *data __UNUSED__, void *context, void *surface, void *image, RGBA_Map_Point *p, int smooth, int level)
1136 re = (Render_Engine *)data;
1137 evas_gl_common_context_target_surface_set(re->gl_context, surface);
1138 re->gl_context->dc = context;
1139 evas_gl_common_image_map4_draw(re->gl_context, image, p, smooth, level);
1143 eng_image_map_surface_new(void *data __UNUSED__, int w, int h, int alpha)
1147 re = (Render_Engine *)data;
1148 return evas_gl_common_image_surface_new(re->gl_context, w, h, alpha);
1152 eng_image_map_surface_free(void *data __UNUSED__, void *surface)
1154 evas_gl_common_image_free(surface);
1158 eng_image_scale_hint_get(void *data __UNUSED__, void *image)
1160 return EVAS_IMAGE_SCALE_HINT_NONE;
1164 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)
1168 re = (Render_Engine *)data;
1169 evas_gl_common_context_target_surface_set(re->gl_context, surface);
1170 re->gl_context->dc = context;
1172 // FIXME: put im into context so we can free it
1173 static RGBA_Image *im = NULL;
1176 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
1177 im->cache_entry.w = re->w;
1178 im->cache_entry.h = re->h;
1179 evas_common_draw_context_font_ext_set(context,
1181 evas_gl_font_texture_new,
1182 evas_gl_font_texture_free,
1183 evas_gl_font_texture_draw);
1184 evas_common_font_draw(im, context, font, x, y, text);
1185 evas_common_draw_context_font_ext_set(context,
1194 eng_canvas_alpha_get(void *data __UNUSED__, void *info __UNUSED__)
1196 // FIXME: support ARGB gl targets!!!
1201 module_open(Evas_Module *em)
1204 /* get whatever engine module we inherit from */
1205 if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
1206 if (_evas_engine_GL_SDL_log_dom < 0)
1207 _evas_engine_GL_SDL_log_dom = eina_log_domain_register("EvasEngineGLSDL", EVAS_DEFAULT_LOG_COLOR);
1208 if (_evas_engine_GL_SDL_log_dom < 0)
1210 EINA_LOG_ERR("Impossible to create a log domain for GL SDL engine.\n");
1213 /* store it for later use */
1215 /* now to override methods */
1216 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
1220 ORD(canvas_alpha_get);
1223 ORD(output_tile_size_set);
1224 ORD(output_redraws_rect_add);
1225 ORD(output_redraws_rect_del);
1226 ORD(output_redraws_clear);
1227 ORD(output_redraws_next_update_get);
1228 ORD(output_redraws_next_update_push);
1229 ORD(context_cutout_add);
1230 ORD(context_cutout_clear);
1232 ORD(output_idle_flush);
1233 ORD(rectangle_draw);
1235 ORD(polygon_point_add);
1236 ORD(polygon_points_clear);
1239 ORD(gradient2_color_np_stop_insert);
1240 ORD(gradient2_clear);
1241 ORD(gradient2_fill_transform_set);
1242 ORD(gradient2_fill_spread_set);
1243 ORD(gradient2_linear_new);
1244 ORD(gradient2_linear_free);
1245 ORD(gradient2_linear_fill_set);
1246 ORD(gradient2_linear_is_opaque);
1247 ORD(gradient2_linear_is_visible);
1248 ORD(gradient2_linear_render_pre);
1249 ORD(gradient2_linear_render_post);
1250 ORD(gradient2_linear_draw);
1251 ORD(gradient2_radial_new);
1252 ORD(gradient2_radial_free);
1253 ORD(gradient2_radial_fill_set);
1254 ORD(gradient2_radial_is_opaque);
1255 ORD(gradient2_radial_is_visible);
1256 ORD(gradient2_radial_render_pre);
1257 ORD(gradient2_radial_render_post);
1258 ORD(gradient2_radial_draw);
1262 ORD(gradient_color_stop_add);
1263 ORD(gradient_alpha_stop_add);
1264 ORD(gradient_color_data_set);
1265 ORD(gradient_alpha_data_set);
1266 ORD(gradient_clear);
1267 ORD(gradient_fill_set);
1268 ORD(gradient_fill_angle_set);
1269 ORD(gradient_fill_spread_set);
1270 ORD(gradient_angle_set);
1271 ORD(gradient_offset_set);
1272 ORD(gradient_direction_set);
1273 ORD(gradient_type_set);
1274 ORD(gradient_is_opaque);
1275 ORD(gradient_is_visible);
1276 ORD(gradient_render_pre);
1277 ORD(gradient_render_post);
1280 ORD(image_new_from_data);
1281 ORD(image_new_from_copied_data);
1283 ORD(image_size_get);
1284 ORD(image_size_set);
1285 ORD(image_dirty_region);
1286 ORD(image_data_get);
1287 ORD(image_data_put);
1288 ORD(image_data_preload_request);
1289 ORD(image_data_preload_cancel);
1290 ORD(image_alpha_set);
1291 ORD(image_alpha_get);
1292 ORD(image_border_set);
1293 ORD(image_border_get);
1295 ORD(image_comment_get);
1296 ORD(image_format_get);
1297 ORD(image_colorspace_set);
1298 ORD(image_colorspace_get);
1299 ORD(image_native_set);
1300 ORD(image_native_get);
1303 ORD(image_scale_hint_set);
1304 ORD(image_scale_hint_get);
1306 ORD(image_map4_draw);
1307 ORD(image_map_surface_new);
1308 ORD(image_map_surface_free);
1310 /* now advertise out own api */
1311 em->functions = (void *)(&func);
1316 module_close(Evas_Module *em)
1318 eina_log_domain_unregister(_evas_engine_GL_SDL_log_dom);
1321 static Evas_Module_Api evas_modapi =
1323 EVAS_MODULE_API_VERSION,
1332 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, gl_sdl);
1334 #ifndef EVAS_STATIC_BUILD_GL_SDL
1335 EVAS_EINA_MODULE_DEFINE(engine, gl_sdl);
1339 _sdl_output_setup (int w, int h, int fullscreen, int noframe)
1341 Render_Engine *re = calloc(1, sizeof(Render_Engine));
1342 SDL_Surface *surface;
1343 int context_attrs[3];
1344 int config_attrs[20];
1345 int major_version, minor_version;
1348 /* if we haven't initialized - init (automatic abort if already done) */
1349 evas_common_cpu_init();
1350 evas_common_blend_init();
1351 evas_common_image_init();
1352 evas_common_convert_init();
1353 evas_common_scale_init();
1354 evas_common_rectangle_init();
1355 evas_common_gradient_init();
1356 evas_common_polygon_init();
1357 evas_common_line_init();
1358 evas_common_font_init();
1359 evas_common_draw_init();
1360 evas_common_tilebuf_init();
1362 if (w <= 0) w = 640;
1363 if (h <= 0) h = 480;
1365 /* GL Initialization */
1366 #ifdef HAVE_SDL_GL_CONTEXT_VERSION
1367 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
1368 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
1370 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
1371 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
1372 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
1373 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
1374 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
1375 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);
1377 surface = SDL_SetVideoMode(w, h, 32, EVAS_SDL_GL_FLAG
1378 | (fullscreen ? SDL_FULLSCREEN : 0)
1379 | (noframe ? SDL_NOFRAME : 0));
1383 CRIT("SDL_SetVideoMode [ %i x %i x 32 ] failed.", w, h);
1384 CRIT("SDL: %s\n", SDL_GetError());
1389 fprintf(stderr, "Screen Depth : %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
1390 fprintf(stderr, "Vendor : %s\n", glGetString(GL_VENDOR));
1391 fprintf(stderr, "Renderer : %s\n", glGetString(GL_RENDERER));
1392 fprintf(stderr, "Version : %s\n", glGetString(GL_VERSION));
1394 re->gl_context = evas_gl_common_context_new();
1395 if (!re->gl_context)
1400 evas_gl_common_context_use(re->gl_context);
1401 evas_gl_common_context_resize(re->gl_context, w, h);
1403 /* End GL Initialization */