8 #include "evas_common.h"/* Also includes international specific stuff */
9 #include "evas_engine.h"
10 int _evas_engine_soft16_sdl_log_dom = -1;
12 /* function tables - filled in later (func and parent func) */
13 static Evas_Func func, pfunc;
15 static Engine_Image_Entry *_sdl16_image_alloc (void);
16 static void _sdl16_image_delete (Engine_Image_Entry *eim);
18 static int _sdl16_image_constructor (Engine_Image_Entry *ie, void* data);
19 static void _sdl16_image_destructor (Engine_Image_Entry *eim);
21 static void _sdl16_image_dirty_region(Engine_Image_Entry *eim, unsigned int x, unsigned int y, unsigned int w, unsigned int h);
23 static int _sdl16_image_dirty (Engine_Image_Entry *dst, const Engine_Image_Entry *src);
25 static int _sdl16_image_size_set (Engine_Image_Entry *dst, const Engine_Image_Entry *src);
27 static int _sdl16_image_update_data (Engine_Image_Entry* dst, void* engine_data);
29 static void _sdl16_image_load (Engine_Image_Entry *eim, const Image_Entry* im);
30 static int _sdl16_image_mem_size_get(Engine_Image_Entry *eim);
33 static void _sdl16_image_debug (const char* context, Engine_Image_Entry* im);
36 static const Evas_Cache_Engine_Image_Func _sdl16_cache_engine_image_cb = {
38 _sdl16_image_alloc /* alloc */,
39 _sdl16_image_delete /* dealloc */,
40 _sdl16_image_constructor /* constructor */,
41 _sdl16_image_destructor /* destructor */,
42 _sdl16_image_dirty_region /* dirty_region */,
43 _sdl16_image_dirty /* dirty */,
44 _sdl16_image_size_set /* size_set */,
45 _sdl16_image_update_data /* update_data */,
46 _sdl16_image_load /* load */,
47 _sdl16_image_mem_size_get /* mem_size_get */,
48 #ifdef DEBUG_SDL /* debug */
55 #define _SDL_UPDATE_PIXELS(EIM) \
56 ((Soft16_Image *) EIM->cache_entry.src)->pixels = EIM->surface->pixels;
58 #define RMASK565 0xf800
59 #define GMASK565 0x07e0
60 #define BMASK565 0x001f
61 #define AMASK565 0x0000
63 /* engine api this module provides */
65 evas_engine_sdl16_info(Evas *e __UNUSED__)
67 Evas_Engine_Info_SDL_16 *info;
68 info = calloc(1, sizeof(Evas_Engine_Info_SDL_16));
69 if (!info) return NULL;
70 info->magic.magic = rand();
75 evas_engine_sdl16_info_free(Evas *e __UNUSED__, void *info)
77 Evas_Engine_Info_SDL_16 *in;
78 in = (Evas_Engine_Info_SDL_16 *)info;
83 _tmp_out_alloc(Render_Engine *re)
86 unsigned int w = 0, h = 0;
88 EINA_INLIST_FOREACH(re->rects, r)
90 if (r->w > (int)w) w = r->w;
91 if (r->h > (int)h) h = r->h;
96 if ((re->tmp_out->cache_entry.w < w) || (re->tmp_out->cache_entry.h < h))
98 evas_cache_image_drop(&re->tmp_out->cache_entry);
107 im = (Soft16_Image *) evas_cache_image_empty(evas_common_soft16_image_cache_get());
108 im->cache_entry.flags.alpha = 0;
109 evas_cache_image_surface_alloc(&im->cache_entry, w, h);
116 _sdl16_output_setup(int w, int h, int rotation, int fullscreen, int noframe, int hwsurface)
119 SDL_Surface *surface;
121 re = calloc(1, sizeof(Render_Engine));
124 /* if we haven't initialized - init (automatic abort if already done) */
125 evas_common_cpu_init();
126 evas_common_blend_init();
127 evas_common_image_init();
128 evas_common_convert_init();
129 evas_common_scale_init();
130 evas_common_rectangle_init();
131 evas_common_polygon_init();
132 evas_common_line_init();
133 evas_common_font_init();
134 evas_common_draw_init();
135 evas_common_tilebuf_init();
136 evas_common_soft16_image_init();
141 re->cache = evas_cache_engine_image_init(&_sdl16_cache_engine_image_cb, evas_common_soft16_image_cache_get());
144 ERR("Evas_Cache_Engine_Image allocation failed!");
149 re->tb = evas_common_tilebuf_new(w, h);
150 /* in preliminary tests 16x16 gave highest framerates */
151 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
155 re->flags.hwsurface = hwsurface;
156 re->flags.fullscreen = fullscreen;
157 re->flags.noframe = noframe;
160 re->update_rects_count = 0;
161 re->update_rects_limit = 0;
162 re->update_rects = NULL;
164 surface = SDL_SetVideoMode(w, h, 16,
165 (hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE)
166 | (fullscreen ? SDL_FULLSCREEN : 0)
167 | (noframe ? SDL_NOFRAME : 0));
170 ERR("SDL_SetVideoMode [ %i x %i x 16 ] failed", w, h);
171 evas_cache_engine_image_shutdown(re->cache);
176 SDL_SetAlpha(surface, SDL_RLEACCEL, 0);
177 SDL_FillRect(surface, NULL, 0);
179 re->soft16_engine_image = (SDL_Engine_Image_Entry *) evas_cache_engine_image_engine(re->cache, surface);
180 if (!re->soft16_engine_image)
182 ERR("Soft16_Image allocation from SDL failed");
183 evas_cache_engine_image_shutdown(re->cache);
193 evas_engine_sdl16_setup(Evas *e, void *in)
195 Evas_Engine_Info_SDL_16 *info = (Evas_Engine_Info_SDL_16 *) in;
197 if (evas_output_method_get(e) != evas_render_method_lookup("software_16_sdl"))
200 SDL_Init(SDL_INIT_NOPARACHUTE);
202 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
204 ERR("SDL_Init failed with %s", SDL_GetError());
209 e->engine.data.output = _sdl16_output_setup(e->output.w, e->output.h,
211 info->info.fullscreen,
213 info->info.hwsurface);
214 if (!e->engine.data.output)
217 e->engine.func = &func;
218 e->engine.data.context = e->engine.func->context_new(e->engine.data.output);
224 evas_engine_sdl16_output_free(void *data)
228 re = (Render_Engine *)data;
229 if (re->tb) evas_common_tilebuf_free(re->tb);
230 if (re->rects) evas_common_tilebuf_free_render_rects(re->rects);
231 if (re->tmp_out) evas_cache_image_drop(&re->tmp_out->cache_entry);
232 if (re->soft16_engine_image) evas_cache_engine_image_drop(&re->soft16_engine_image->cache_entry);
235 evas_common_font_shutdown();
236 evas_common_image_shutdown();
237 evas_common_soft16_image_shutdown();
241 evas_engine_sdl16_output_resize(void *data, int w, int h)
243 Render_Engine *re = data;
244 SDL_Surface *surface;
246 if ((re->w == w) && (re->h == h)) return;
248 evas_cache_engine_image_drop(&re->soft16_engine_image->cache_entry);
250 evas_common_tilebuf_free(re->tb);
253 re->tb = evas_common_tilebuf_new(w, h);
255 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
257 surface = SDL_SetVideoMode(w, h, 16,
258 (re->flags.hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE)
259 | (re->flags.fullscreen ? SDL_FULLSCREEN : 0)
260 | (re->flags.noframe ? SDL_NOFRAME : 0));
263 ERR("Unable to change the resolution to : %ix%i", w, h);
266 re->soft16_engine_image = (SDL_Engine_Image_Entry *) evas_cache_engine_image_engine(re->cache, surface);
267 if (!re->soft16_engine_image)
269 ERR("RGBA_Image allocation from SDL failed");
273 SDL_FillRect(surface, NULL, 0);
277 evas_cache_image_drop(&re->tmp_out->cache_entry);
283 evas_engine_sdl16_output_tile_size_set(void *data, int w, int h)
287 re = (Render_Engine *)data;
288 evas_common_tilebuf_set_tile_size(re->tb, w, h);
292 evas_engine_sdl16_output_redraws_rect_add(void *data, int x, int y, int w, int h)
296 re = (Render_Engine *)data;
297 evas_common_tilebuf_add_redraw(re->tb, x, y, w, h);
301 evas_engine_sdl16_output_redraws_rect_del(void *data, int x, int y, int w, int h)
305 re = (Render_Engine *)data;
306 evas_common_tilebuf_del_redraw(re->tb, x, y, w, h);
310 evas_engine_sdl16_output_redraws_clear(void *data)
314 re = (Render_Engine *)data;
315 evas_common_tilebuf_clear(re->tb);
319 evas_engine_sdl16_output_redraws_next_update_get(void *data,
320 int *x, int *y, int *w, int *h,
321 int *cx, int *cy, int *cw, int *ch)
323 Render_Engine *re = data;
324 Tilebuf_Rect *tb_rect;
334 re->rects = evas_common_tilebuf_get_render_rects(re->tb);
335 re->cur_rect = re->rects;
336 if (re->rot != 0) _tmp_out_alloc(re); /* grows if required */
340 if (re->rects) evas_common_tilebuf_free_render_rects(re->rects);
345 tb_rect = re->cur_rect;
346 *cx = *x = tb_rect->x;
347 *cy = *y = tb_rect->y;
348 *cw = *w = tb_rect->w;
349 *ch = *h = tb_rect->h;
350 re->cur_rect = (Tilebuf_Rect *)((EINA_INLIST_GET(re->cur_rect))->next);
353 evas_common_tilebuf_free_render_rects(re->rects);
369 /* Return the "fake" surface so it is passed to the drawing routines. */
370 return re->soft16_engine_image;
374 _blit_rot_90(Soft16_Image *dst, const Soft16_Image *src,
375 int out_x, int out_y, int w, int h)
381 dp = dst->pixels + (out_x +
382 (w + out_y - 1) * dst->stride);
384 for (y = 0; y < h; y++)
386 DATA16 *dp_itr, *sp_itr;
391 for (x = 0; x < w; x++)
396 dp_itr -= dst->stride;
404 _blit_rot_180(Soft16_Image *dst, const Soft16_Image *src,
405 int out_x, int out_y, int w, int h)
411 dp = dst->pixels + ((w + out_x - 1) +
412 (h + out_y - 1) * dst->stride);
414 for (y = 0; y < h; y++)
416 DATA16 *dp_itr, *sp_itr;
421 for (x = 0; x < w; x++)
434 _blit_rot_270(Soft16_Image *dst, const Soft16_Image *src,
435 int out_x, int out_y, int w, int h)
441 dp = dst->pixels + ((h + out_x - 1) +
442 out_y * dst->stride);
444 for (y = 0; y < h; y++)
446 DATA16 *dp_itr, *sp_itr;
451 for (x = 0; x < w; x++)
456 dp_itr += dst->stride;
464 _tmp_out_process(Render_Engine *re, int out_x, int out_y, int w, int h)
468 d = (Soft16_Image *) re->soft16_engine_image->cache_entry.src;
471 if ((w < 1) || (h < 1) ||
472 (out_x >= (int)d->cache_entry.w) || (out_y >= (int)d->cache_entry.h))
476 _blit_rot_90(d, s, out_x, out_y, w, h);
477 else if (re->rot == 180)
478 _blit_rot_180(d, s, out_x, out_y, w, h);
479 else if (re->rot == 270)
480 _blit_rot_270(d, s, out_x, out_y, w, h);
484 evas_engine_sdl16_output_redraws_next_update_push(void *data, void *surface __UNUSED__,
485 int x, int y, int w, int h)
487 Render_Engine *re = data;
490 if (re->update_rects_count + 1 > re->update_rects_limit)
492 re->update_rects_limit += 8;
493 re->update_rects = realloc(re->update_rects, sizeof (SDL_Rect) * re->update_rects_limit);
507 rect.y = re->w - w - x;
512 rect.x = re->w - w - x;
513 rect.y = re->h - h - y;
516 rect.x = re->h - h - y;
525 re->update_rects[re->update_rects_count] = rect;
528 _tmp_out_process(re, rect.x, rect.y, w, h);
530 ++re->update_rects_count;
534 evas_engine_sdl16_output_flush(void *data)
536 Render_Engine *re = data;
538 if (re->update_rects_count > 0)
539 SDL_UpdateRects(re->soft16_engine_image->surface, re->update_rects_count, re->update_rects);
541 re->update_rects_count = 0;
545 evas_engine_sdl16_output_idle_flush(void *data)
549 re = (Render_Engine *)data;
552 evas_cache_image_drop(&re->tmp_out->cache_entry);
558 evas_engine_sdl16_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
560 Render_Engine* re = (Render_Engine*) data;;
563 return evas_cache_engine_image_request(re->cache, file, key, lo, NULL, error);
567 evas_engine_sdl16_image_alpha_get(void *data __UNUSED__, void *image)
569 SDL_Engine_Image_Entry *eim = image;
573 im = (Soft16_Image *) eim->cache_entry.src;
574 if (im->cache_entry.flags.alpha) return 1;
579 evas_engine_sdl16_image_size_get(void *data __UNUSED__, void *image, int *w, int *h)
581 SDL_Engine_Image_Entry *eim;
584 if (w) *w = eim->cache_entry.w;
585 if (h) *h = eim->cache_entry.h;
589 evas_engine_sdl16_image_colorspace_get(void *data __UNUSED__, void *image __UNUSED__)
591 return EVAS_COLORSPACE_RGB565_A5P;
595 evas_engine_sdl16_image_colorspace_set(void *data __UNUSED__, void *image __UNUSED__, int cspace __UNUSED__)
597 /* FIXME: Not implemented. */
601 evas_engine_sdl16_image_new_from_copied_data(void *data,
604 int alpha, int cspace)
606 Render_Engine *re = data;
608 if (cspace != EVAS_COLORSPACE_RGB565_A5P)
610 WRN("Unsupported colorspace %d in %s() (%s:%d)",
611 cspace, __FUNCTION__, __FILE__, __LINE__);
615 WRN("s image_data: %p", image_data);
617 return evas_cache_engine_image_copied_data(re->cache,
620 alpha, cspace, NULL);
624 evas_engine_sdl16_image_new_from_data(void *data, int w, int h, DATA32* image_data, int alpha, int cspace)
626 Render_Engine *re = data;
628 if (cspace != EVAS_COLORSPACE_RGB565_A5P)
630 WRN("Unsupported colorspace %d in %s() (%s:%d)",
631 cspace, __FUNCTION__, __FILE__, __LINE__);
635 return evas_cache_engine_image_data(re->cache,
638 alpha, cspace, NULL);
642 evas_engine_sdl16_image_free(void *data __UNUSED__, void *image)
644 SDL_Engine_Image_Entry *eim = image;
646 evas_cache_engine_image_drop(&eim->cache_entry);
650 evas_engine_sdl16_image_size_set(void *data __UNUSED__, void *image, int w, int h)
652 SDL_Engine_Image_Entry *eim = image;
654 return evas_cache_engine_image_size_set(&eim->cache_entry, w, h);
658 evas_engine_sdl16_image_dirty_region(void *data __UNUSED__,
660 int x, int y, int w, int h)
662 SDL_Engine_Image_Entry *eim = image;
664 return evas_cache_engine_image_dirty(&eim->cache_entry, x, y, w, h);
668 evas_engine_sdl16_image_data_get(void *data __UNUSED__, void *image,
669 int to_write, DATA32** image_data, int *err)
671 SDL_Engine_Image_Entry *eim = image;
680 im = (Soft16_Image *) eim->cache_entry.src;
681 error = evas_cache_image_load_data(&im->cache_entry);
684 eim = (SDL_Engine_Image_Entry *) evas_cache_engine_image_alone(&eim->cache_entry,
687 /* FIXME: Handle colorspace conversion correctly. */
688 if (image_data) *image_data = (DATA32 *) im->pixels;
690 if (err) *err = error;
695 evas_engine_sdl16_image_data_put(void *data, void *image, DATA32* image_data)
697 SDL_Engine_Image_Entry *eim = image;
698 SDL_Engine_Image_Entry *eim_new;
699 Render_Engine *re = data;
702 if (!eim) return NULL;
703 im = (Soft16_Image *) eim->cache_entry.src;
705 /* FIXME: Handle colorspace conversion correctly. */
706 if ((DATA16 *) image_data == im->pixels) return eim;
708 eim_new = (SDL_Engine_Image_Entry *) evas_cache_engine_image_data(re->cache,
709 eim->cache_entry.w, eim->cache_entry.h,
711 func.image_alpha_get(data, eim),
712 func.image_colorspace_get(data, eim),
714 evas_cache_engine_image_drop(&eim->cache_entry);
720 evas_engine_sdl16_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
722 SDL_Engine_Image_Entry *eim = image;
726 im = (Soft16_Image *) eim->cache_entry.src;
728 evas_cache_image_preload_data(&im->cache_entry, target);
732 evas_engine_sdl16_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
734 SDL_Engine_Image_Entry *eim = image;
738 im = (Soft16_Image *) eim->cache_entry.src;
740 evas_cache_image_preload_cancel(&im->cache_entry, target);
744 evas_engine_sdl16_image_alpha_set(void *data __UNUSED__, void *image, int has_alpha)
746 SDL_Engine_Image_Entry *eim = image;
749 if (!eim) return NULL;
751 im = (Soft16_Image *) eim->cache_entry.src;
753 if (im->cache_entry.flags.alpha == has_alpha) return eim;
755 eim = (SDL_Engine_Image_Entry *) evas_cache_engine_image_alone(&eim->cache_entry,
758 im = (Soft16_Image *) eim->cache_entry.src;
760 im->cache_entry.flags.alpha = has_alpha;
761 eim = (SDL_Engine_Image_Entry *) evas_cache_engine_image_dirty(&eim->cache_entry, 0, 0, eim->cache_entry.w, eim->cache_entry.h);
767 evas_engine_sdl16_image_border_set(void *data __UNUSED__, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
773 evas_engine_sdl16_image_border_get(void *data __UNUSED__, void *image __UNUSED__, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
775 /* FIXME: need to know what evas expect from this call */
779 evas_engine_sdl16_image_draw(void *data __UNUSED__, void *context, void *surface, void *image,
780 int src_region_x, int src_region_y, int src_region_w, int src_region_h,
781 int dst_region_x, int dst_region_y, int dst_region_w, int dst_region_h,
784 SDL_Engine_Image_Entry *eim = image;
785 SDL_Engine_Image_Entry *dst = surface;
787 int mustlock_dst = 0;
789 evas_cache_engine_image_load_data(&eim->cache_entry);
791 /* Fallback to software method */
792 if (SDL_MUSTLOCK(dst->surface))
795 SDL_LockSurface(dst->surface);
796 _SDL_UPDATE_PIXELS(dst);
799 if (eim->surface && SDL_MUSTLOCK(eim->surface))
802 SDL_LockSurface(eim->surface);
803 _SDL_UPDATE_PIXELS(eim);
806 evas_common_soft16_image_draw((Soft16_Image *) eim->cache_entry.src,
807 (Soft16_Image *) dst->cache_entry.src,
809 src_region_x, src_region_y, src_region_w, src_region_h,
810 dst_region_x, dst_region_y, dst_region_w, dst_region_h,
814 SDL_UnlockSurface(eim->surface);
817 SDL_UnlockSurface(dst->surface);
821 evas_engine_sdl16_image_map_draw(void *data __UNUSED__, void *context __UNUSED__, void *surface __UNUSED__, void *image __UNUSED__, int npoints __UNUSED__, RGBA_Map_Point *p __UNUSED__, int smooth __UNUSED__, int level __UNUSED__)
826 evas_engine_sdl16_image_scale_hint_set(void *data __UNUSED__, void *image __UNUSED__, int hint __UNUSED__)
831 evas_engine_sdl16_image_scale_hint_get(void *data __UNUSED__, void *image __UNUSED__)
833 return EVAS_IMAGE_SCALE_HINT_NONE;
838 evas_engine_sdl16_image_cache_flush(void *data)
840 Render_Engine *re = (Render_Engine*) data;
843 size = evas_cache_engine_image_get(re->cache);
844 evas_cache_engine_image_set(re->cache, 0);
845 evas_cache_engine_image_set(re->cache, size);
849 evas_engine_sdl16_image_cache_set(void *data, int bytes)
851 Render_Engine *re = (Render_Engine*) data;
853 evas_cache_engine_image_set(re->cache, bytes);
857 evas_engine_sdl16_image_cache_get(void *data)
859 Render_Engine *re = (Render_Engine*) data;
861 return evas_cache_engine_image_get(re->cache);
865 evas_engine_sdl16_image_comment_get(void *data __UNUSED__, void *image __UNUSED__, char *key __UNUSED__)
871 evas_engine_sdl16_image_format_get(void *data __UNUSED__, void *image __UNUSED__)
873 /* FIXME: need to know what evas expect from this call */
878 evas_engine_sdl16_font_draw(void *data __UNUSED__, void *context, void *surface, void *font, int x, int y, int w __UNUSED__, int h __UNUSED__, int ow __UNUSED__, int oh __UNUSED__, const Evas_Text_Props *intl_props)
880 static RGBA_Image *im = NULL;
881 SDL_Engine_Image_Entry *eim = surface;
882 Soft16_Image *dst = (Soft16_Image *) eim->cache_entry.src;
886 im = (RGBA_Image *) evas_cache_image_empty(evas_common_image_cache_get());
887 evas_cache_image_surface_alloc(&im->cache_entry, dst->cache_entry.w, dst->cache_entry.h);
889 if (eim->surface && SDL_MUSTLOCK(eim->surface))
892 SDL_LockSurface(eim->surface);
893 _SDL_UPDATE_PIXELS(eim);
895 evas_common_draw_context_font_ext_set(context,
897 evas_common_soft16_font_glyph_new,
898 evas_common_soft16_font_glyph_free,
899 evas_common_soft16_font_glyph_draw);
900 evas_common_font_draw(im, context, font, x, y, intl_props);
901 evas_common_draw_context_font_ext_set(context,
908 SDL_UnlockSurface(eim->surface);
912 evas_engine_sdl16_line_draw(void *data __UNUSED__, void *context, void *surface, int x1, int y1, int x2, int y2)
914 SDL_Engine_Image_Entry *eim = surface;
917 if (eim->surface && SDL_MUSTLOCK(eim->surface))
920 SDL_LockSurface(eim->surface);
921 _SDL_UPDATE_PIXELS(eim);
924 evas_common_soft16_line_draw((Soft16_Image *) eim->cache_entry.src,
929 SDL_UnlockSurface(eim->surface);
933 evas_engine_sdl16_rectangle_draw(void *data __UNUSED__, void *context, void *surface, int x, int y, int w, int h)
935 SDL_Engine_Image_Entry *eim = surface;
936 #if ENGINE_SDL_PRIMITIVE
937 RGBA_Draw_Context *dc = context;
942 #if ENGINE_SDL_PRIMITIVE
943 if (A_VAL(&dc->col.col) != 0x00)
945 if (A_VAL(&dc->col.col) != 0xFF)
948 if (eim->surface && SDL_MUSTLOCK(eim->surface))
951 SDL_LockSurface(eim->surface);
952 _SDL_UPDATE_PIXELS(eim);
955 im = (Soft16_Image *) eim->cache_entry.src;
957 evas_common_soft16_rectangle_draw(im, context, x, y, w, h);
960 SDL_UnlockSurface(eim->surface);
961 #if ENGINE_SDL_PRIMITIVE
971 cliprect.x = dc->clip.x;
972 cliprect.y = dc->clip.y;
973 cliprect.w = dc->clip.w;
974 cliprect.h = dc->clip.h;
976 SDL_SetClipRect(eim->surface, &cliprect);
984 SDL_FillRect(eim->surface, &dstrect, SDL_MapRGBA(eim->surface->format, R_VAL(&dc->col.col), G_VAL(&dc->col.col), B_VAL(&dc->col.col), 0xFF));
987 SDL_SetClipRect(eim->surface, NULL);
994 evas_engine_sdl16_polygon_draw(void *data __UNUSED__, void *context, void *surface, void *polygon, int x, int y)
996 SDL_Engine_Image_Entry *eim = surface;
999 if (eim->surface && SDL_MUSTLOCK(eim->surface))
1002 SDL_LockSurface(eim->surface);
1003 _SDL_UPDATE_PIXELS(eim);
1006 evas_common_soft16_polygon_draw((Soft16_Image *) eim->cache_entry.src, context, polygon, x, y);
1009 SDL_UnlockSurface(eim->surface);
1013 evas_engine_sdl16_image_stride_get(void *data __UNUSED__, void *image, int *stride)
1015 SDL_Engine_Image_Entry *eim = image;
1017 if (stride) *stride = 0;
1019 if (stride) *stride = ((Soft16_Image*) eim->cache_entry.src)->stride;
1023 evas_engine_sdl16_canvas_alpha_get(void *data __UNUSED__, void *context __UNUSED__)
1028 /* module advertising code */
1030 module_open(Evas_Module *em)
1033 /* get whatever engine module we inherit from */
1034 if (!_evas_module_engine_inherit(&pfunc, "software_16")) return 0;
1035 _evas_engine_soft16_sdl_log_dom = eina_log_domain_register
1036 ("evas-software_16_sdl", EVAS_DEFAULT_LOG_COLOR);
1037 if (_evas_engine_soft16_sdl_log_dom < 0)
1039 EINA_LOG_ERR("Can not create a module log domain.");
1043 /* store it for later use */
1045 /* now to override methods */
1046 #define ORD(f) EVAS_API_OVERRIDE(f, &func, evas_engine_sdl16_)
1050 ORD(canvas_alpha_get);
1053 ORD(output_tile_size_set);
1054 ORD(output_redraws_rect_add);
1055 ORD(output_redraws_rect_del);
1056 ORD(output_redraws_clear);
1057 ORD(output_redraws_next_update_get);
1058 ORD(output_redraws_next_update_push);
1060 ORD(output_idle_flush);
1062 ORD(image_alpha_get);
1063 ORD(image_size_get);
1064 ORD(image_colorspace_get);
1065 ORD(image_colorspace_set);
1066 ORD(image_new_from_copied_data);
1067 ORD(image_new_from_data);
1069 ORD(image_size_set);
1070 ORD(image_dirty_region);
1071 ORD(image_data_get);
1072 ORD(image_data_put);
1073 ORD(image_data_preload_request);
1074 ORD(image_data_preload_cancel);
1075 ORD(image_alpha_set);
1076 ORD(image_border_set);
1077 ORD(image_border_get);
1079 ORD(image_map_draw);
1080 ORD(image_cache_flush);
1081 ORD(image_cache_set);
1082 ORD(image_cache_get);
1083 ORD(image_comment_get);
1084 ORD(image_format_get);
1085 ORD(image_stride_get);
1088 ORD(rectangle_draw);
1091 ORD(image_scale_hint_set);
1092 ORD(image_scale_hint_get);
1094 /* now advertise out own api */
1095 em->functions = (void *)(&func);
1100 module_close(Evas_Module *em __UNUSED__)
1102 eina_log_domain_unregister(_evas_engine_soft16_sdl_log_dom);
1105 static Evas_Module_Api evas_modapi =
1107 EVAS_MODULE_API_VERSION,
1116 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, software_16_sdl);
1118 #ifndef EVAS_STATIC_BUILD_SOFTWARE_SDL
1119 EVAS_EINA_MODULE_DEFINE(engine, software_16_sdl);
1122 static Engine_Image_Entry*
1123 _sdl16_image_alloc(void)
1125 SDL_Engine_Image_Entry *new;
1127 new = calloc(1, sizeof (SDL_Engine_Image_Entry));
1129 return (Engine_Image_Entry *) new;
1133 _sdl16_image_delete(Engine_Image_Entry *eim)
1139 _sdl16_image_constructor(Engine_Image_Entry *ie, void* data __UNUSED__)
1141 SDL_Surface *sdl = NULL;
1142 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) ie;
1145 im = (Soft16_Image *) ie->src;
1149 /* FIXME: Take care of CSPACE */
1150 sdl = SDL_CreateRGBSurfaceFrom(im->pixels,
1153 RMASK565, GMASK565, BMASK565, AMASK565);
1155 eim->flags.engine_surface = 0;
1158 return EVAS_LOAD_ERROR_NONE;
1162 _sdl16_image_destructor(Engine_Image_Entry *eim)
1164 SDL_Engine_Image_Entry *seie = (SDL_Engine_Image_Entry *) eim;
1166 if (seie->surface && !seie->flags.engine_surface)
1167 SDL_FreeSurface(seie->surface);
1168 seie->surface = NULL;
1172 _sdl16_image_dirty_region(Engine_Image_Entry *eim, unsigned int x, unsigned int y, unsigned int w, unsigned int h)
1174 SDL_Engine_Image_Entry *dst;
1177 dst = (SDL_Engine_Image_Entry *) eim;
1179 SDL_UpdateRect(dst->surface, x, y, w, h);
1181 im = (RGBA_Image *)eim->src;
1182 im->flags |= RGBA_IMAGE_IS_DIRTY;
1186 _sdl16_image_dirty(Engine_Image_Entry *dst, const Engine_Image_Entry *src __UNUSED__)
1188 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) dst;
1189 SDL_Surface *sdl = NULL;
1192 im = (Soft16_Image *) dst->src;
1194 /* FIXME: Take care of CSPACE */
1195 sdl = SDL_CreateRGBSurfaceFrom(im->pixels,
1198 RMASK565, GMASK565, BMASK565, AMASK565);
1200 eim->flags.engine_surface = 0;
1206 _sdl16_image_size_set(Engine_Image_Entry *dst, const Engine_Image_Entry *src __UNUSED__)
1208 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) dst;
1212 im = (Soft16_Image *) dst->src;
1214 /* FIXME: handle im == NULL */
1215 sdl = SDL_CreateRGBSurfaceFrom(im->pixels,
1218 RMASK565, GMASK565, BMASK565, AMASK565);
1226 _sdl16_image_update_data(Engine_Image_Entry* dst, void* engine_data)
1228 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) dst;
1229 SDL_Surface *sdl = NULL;
1232 im = (Soft16_Image *) dst->src;
1240 im->pixels = sdl->pixels;
1241 im->stride = sdl->pitch / 2;
1242 im->flags.free_pixels = 0;
1243 /* im->alpha = calloc(1, sizeof (DATA8) * _calc_stride(sdl->w) * sdl->h); */
1244 /* im->flags.free_alpha = 0; */
1245 /* im->flags.have_alpha = 1; */
1247 im->flags.free_alpha = 0;
1248 im->cache_entry.flags.alpha = 0;
1250 dst->src->w = sdl->w;
1251 dst->src->h = sdl->h;
1258 SDL_FreeSurface(eim->surface);
1259 /* FIXME: Take care of CSPACE */
1260 sdl = SDL_CreateRGBSurfaceFrom(im->pixels,
1263 RMASK565, GMASK565, BMASK565, AMASK565);
1272 _sdl16_image_load(Engine_Image_Entry *eim, const Image_Entry* ie_im)
1274 SDL_Engine_Image_Entry *load = (SDL_Engine_Image_Entry *) eim;
1281 im = (Soft16_Image *) ie_im;
1283 sdl = SDL_CreateRGBSurfaceFrom(im->pixels,
1286 RMASK565, GMASK565, BMASK565, AMASK565);
1287 load->surface = sdl;
1292 _sdl16_image_mem_size_get(Engine_Image_Entry *eim)
1294 SDL_Engine_Image_Entry *seie = (SDL_Engine_Image_Entry *) eim;
1297 /* FIXME: Count surface size. */
1299 size = sizeof (SDL_Surface) + sizeof (SDL_PixelFormat);
1306 _sdl16_image_debug(const char* context, Engine_Image_Entry* im)