8 #include "evas_engine.h"
10 /* #define DEBUG_SDL */
12 static Evas_Func func = {};
13 static Evas_Func pfunc = {};
15 static void* _sdl_output_setup (int w, int h, int fullscreen, int noframe, int alpha, int hwsurface);
17 static Engine_Image_Entry *_sdl_image_alloc (void);
18 static void _sdl_image_delete (Engine_Image_Entry *eim);
20 static int _sdl_image_constructor (Engine_Image_Entry*, void* data);
21 static void _sdl_image_destructor (Engine_Image_Entry *eim);
23 static void _sdl_image_dirty_region(Engine_Image_Entry *eim, int x, int y, int w, int h);
25 static int _sdl_image_dirty (Engine_Image_Entry *dst, const Engine_Image_Entry *src);
27 static int _sdl_image_size_set (Engine_Image_Entry *dst, const Engine_Image_Entry *src);
29 static int _sdl_image_update_data (Engine_Image_Entry* dst, void* engine_data);
31 static void _sdl_image_load (Engine_Image_Entry *eim, const Image_Entry* im);
32 static int _sdl_image_mem_size_get(Engine_Image_Entry *eim);
35 static void _sdl_image_debug (const char* context, Engine_Image_Entry* im);
38 static const Evas_Cache_Engine_Image_Func _sdl_cache_engine_image_cb = {
40 _sdl_image_alloc /* alloc */,
41 _sdl_image_delete /* dealloc */,
42 _sdl_image_constructor /* constructor */,
43 _sdl_image_destructor /* destructor */,
44 _sdl_image_dirty_region /* dirty_region */,
45 _sdl_image_dirty /* dirty */,
46 _sdl_image_size_set /* size_set */,
47 _sdl_image_update_data /* update_data */,
48 _sdl_image_load /* load */,
49 _sdl_image_mem_size_get /* mem_size_get */,
50 #ifdef DEBUG_SDL /* debug */
57 #define _SDL_UPDATE_PIXELS(EIM) \
58 ((RGBA_Image *) EIM->cache_entry.src)->image.data = EIM->surface->pixels;
60 #define RMASK 0x00ff0000
61 #define GMASK 0x0000ff00
62 #define BMASK 0x000000ff
63 #define AMASK 0xff000000
65 /* SDL engine info function */
67 evas_engine_sdl_info (Evas* e)
69 Evas_Engine_Info_SDL* info = calloc(1, sizeof (Evas_Engine_Info_SDL));
74 info->magic.magic = rand();
80 evas_engine_sdl_info_free (Evas* e, void* info)
82 Evas_Engine_Info_SDL* in = (Evas_Engine_Info_SDL*) info;
88 /* SDL engine output manipulation function */
90 evas_engine_sdl_setup (Evas* e, void* in)
92 Evas_Engine_Info_SDL* info = (Evas_Engine_Info_SDL*) in;
94 /* if we arent set to sdl, why the hell do we get called?! */
95 if (evas_output_method_get(e) != evas_render_method_lookup("software_sdl"))
98 SDL_Init(SDL_INIT_NOPARACHUTE);
100 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
102 fprintf(stderr, "SDL_Init failed with %s\n", SDL_GetError());
106 /* lets just set up */
107 e->engine.data.output = _sdl_output_setup(e->output.w, e->output.h,
108 info->info.fullscreen,
111 info->info.hwsurface);
113 if (!e->engine.data.output)
116 e->engine.func = &func;
117 e->engine.data.context = e->engine.func->context_new(e->engine.data.output);
121 evas_engine_sdl_output_free (void *data)
123 Render_Engine* re = data;
126 evas_cache_engine_image_shutdown(re->cache);
128 evas_common_tilebuf_free(re->tb);
130 evas_common_tilebuf_free_render_rects(re->rects);
132 if (re->update_rects)
133 free(re->update_rects);
136 /* evas_common_font_shutdown(); */
137 evas_common_image_shutdown();
139 SDL_QuitSubSystem(SDL_INIT_VIDEO);
143 evas_engine_sdl_output_resize (void *data, int w, int h)
146 Render_Engine *re = data;
147 SDL_Surface *surface;
149 if (w == re->tb->outbuf_w && h == re->tb->outbuf_h)
152 /* Destroy the current screen */
153 evas_cache_engine_image_drop(&re->rgba_engine_image->cache_entry);
156 evas_common_tilebuf_free(re->tb);
157 re->tb = evas_common_tilebuf_new(w, h);
159 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
161 /* Build the new screen */
162 surface = SDL_SetVideoMode(w, h, 32,
163 (re->flags.hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE)
164 | (re->flags.fullscreen ? SDL_FULLSCREEN : 0)
165 | (re->flags.noframe ? SDL_NOFRAME : 0)
166 | (re->flags.alpha ? SDL_SRCALPHA : 0));
170 fprintf(stderr, "Unable to change the resolution to : %ix%i\n", w, h);
173 re->rgba_engine_image = (SDL_Engine_Image_Entry *) evas_cache_engine_image_engine(re->cache, surface);
174 if (!re->rgba_engine_image)
176 fprintf(stderr, "RGBA_Image allocation from SDL failed\n");
180 SDL_FillRect(surface, NULL, 0);
184 evas_engine_sdl_output_tile_size_set (void *data, int w, int h)
186 Render_Engine* re = (Render_Engine*) data;
188 evas_common_tilebuf_set_tile_size(re->tb, w, h);
192 evas_engine_sdl_output_redraws_rect_add (void *data, int x, int y, int w, int h)
194 Render_Engine* re = (Render_Engine*) data;
196 evas_common_tilebuf_add_redraw(re->tb, x, y, w, h);
200 evas_engine_sdl_output_redraws_rect_del (void *data, int x, int y, int w, int h)
202 Render_Engine* re = (Render_Engine*) data;
204 evas_common_tilebuf_del_redraw(re->tb, x, y, w, h);
208 evas_engine_sdl_output_redraws_clear (void *data)
210 Render_Engine* re = (Render_Engine*) data;
212 evas_common_tilebuf_clear(re->tb);
216 evas_engine_sdl_output_redraws_next_update_get (void *data,
217 int *x, int *y, int *w, int *h,
218 int *cx, int *cy, int *cw, int *ch)
220 Render_Engine *re = data;
221 Tilebuf_Rect *tb_rect;
231 re->rects = evas_common_tilebuf_get_render_rects(re->tb);
232 re->cur_rect = (Evas_Object_List *) re->rects;
237 tb_rect = (Tilebuf_Rect*) re->cur_rect;
238 *cx = *x = tb_rect->x;
239 *cy = *y = tb_rect->y;
240 *cw = *w = tb_rect->w;
241 *ch = *h = tb_rect->h;
242 re->cur_rect = re->cur_rect->next;
245 evas_common_tilebuf_free_render_rects(re->rects);
255 SDL_FillRect(re->rgba_engine_image->surface, &rect, 0);
257 /* Return the "fake" surface so it is passed to the drawing routines. */
258 return re->rgba_engine_image;
262 evas_engine_sdl_output_redraws_next_update_push (void *data, void *surface,
263 int x, int y, int w, int h)
265 Render_Engine *re = (Render_Engine *) data;
267 if (re->update_rects_count + 1 > re->update_rects_limit)
269 re->update_rects_limit += 8;
270 re->update_rects = realloc(re->update_rects, sizeof (SDL_Rect) * re->update_rects_limit);
273 re->update_rects[re->update_rects_count].x = x;
274 re->update_rects[re->update_rects_count].y = y;
275 re->update_rects[re->update_rects_count].w = w;
276 re->update_rects[re->update_rects_count].h = h;
278 ++re->update_rects_count;
280 evas_common_cpu_end_opt();
284 _sdl_image_dirty_region(Engine_Image_Entry *eim, int x, int y, int w, int h)
286 SDL_Engine_Image_Entry *dst;
289 dst = (SDL_Engine_Image_Entry *) eim;
291 SDL_UpdateRect(dst->surface, x, y, w, h);
293 im = (RGBA_Image *)eim->src;
294 im->flags |= RGBA_IMAGE_IS_DIRTY;
298 evas_engine_sdl_output_flush(void *data)
300 Render_Engine *re = (Render_Engine *) data;
302 if (re->update_rects_count > 0)
303 SDL_UpdateRects(re->rgba_engine_image->surface, re->update_rects_count, re->update_rects);
305 re->update_rects_count = 0;
310 evas_engine_sdl_output_idle_flush(void *data)
320 evas_engine_sdl_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
322 Render_Engine* re = (Render_Engine*) data;;
325 return evas_cache_engine_image_request(re->cache, file, key, lo, NULL, error);
329 evas_engine_sdl_image_alpha_get(void *data, void *image)
331 SDL_Engine_Image_Entry *eim = image;
335 im = (RGBA_Image *) eim->cache_entry.src;
336 switch (eim->cache_entry.src->space)
338 case EVAS_COLORSPACE_ARGB8888:
339 if (im->cache_entry.flags.alpha) return 1;
347 evas_engine_sdl_image_size_get(void *data, void *image, int *w, int *h)
349 SDL_Engine_Image_Entry *eim;
352 if (w) *w = eim->cache_entry.src->w;
353 if (h) *h = eim->cache_entry.src->h;
357 evas_engine_sdl_image_colorspace_get(void *data, void *image)
359 SDL_Engine_Image_Entry *eim = image;
361 if (!eim) return EVAS_COLORSPACE_ARGB8888;
362 return eim->cache_entry.src->space;
366 evas_engine_sdl_image_colorspace_set(void *data, void *image, int cspace)
368 SDL_Engine_Image_Entry *eim = image;
371 if (eim->cache_entry.src->space == cspace) return;
373 evas_cache_engine_image_colorspace(&eim->cache_entry, cspace, NULL);
377 evas_engine_sdl_image_new_from_copied_data(void *data,
380 int alpha, int cspace)
382 Render_Engine *re = (Render_Engine*) data;
384 return evas_cache_engine_image_copied_data(re->cache, w, h, image_data, alpha, cspace, NULL);
388 evas_engine_sdl_image_new_from_data(void *data, int w, int h, DATA32* image_data, int alpha, int cspace)
390 Render_Engine *re = (Render_Engine*) data;
392 return evas_cache_engine_image_data(re->cache, w, h, image_data, alpha, cspace, NULL);
396 evas_engine_sdl_image_free(void *data, void *image)
398 SDL_Engine_Image_Entry *eim = image;
402 evas_cache_engine_image_drop(&eim->cache_entry);
406 evas_engine_sdl_image_size_set(void *data, void *image, int w, int h)
408 SDL_Engine_Image_Entry *eim = image;
412 return evas_cache_engine_image_size_set(&eim->cache_entry, w, h);
416 evas_engine_sdl_image_dirty_region(void *data,
418 int x, int y, int w, int h)
420 SDL_Engine_Image_Entry *eim = image;
424 return evas_cache_engine_image_dirty(&eim->cache_entry, x, y, w, h);
428 evas_engine_sdl_image_data_get(void *data, void *image,
429 int to_write, DATA32** image_data)
431 SDL_Engine_Image_Entry *eim = image;
441 im = (RGBA_Image *) eim->cache_entry.src;
443 switch (eim->cache_entry.src->space)
445 case EVAS_COLORSPACE_ARGB8888:
447 eim = (SDL_Engine_Image_Entry *) evas_cache_engine_image_dirty(&eim->cache_entry, 0, 0, eim->cache_entry.src->w, eim->cache_entry.src->h);
449 evas_cache_engine_image_load_data(&eim->cache_entry);
450 *image_data = im->image.data;
452 case EVAS_COLORSPACE_YCBCR422P709_PL:
453 case EVAS_COLORSPACE_YCBCR422P601_PL:
454 *image_data = im->cs.data;
464 evas_engine_sdl_image_data_put(void *data, void *image, DATA32* image_data)
466 SDL_Engine_Image_Entry *eim = image;
467 Render_Engine *re = data;
470 if (!eim) return NULL;
471 im = (RGBA_Image*) eim->cache_entry.src;
473 switch (eim->cache_entry.src->space)
475 case EVAS_COLORSPACE_ARGB8888:
476 if (image_data != im->image.data)
478 evas_cache_engine_image_drop(&eim->cache_entry);
479 eim = (SDL_Engine_Image_Entry *) evas_cache_engine_image_data(re->cache,
480 eim->cache_entry.w, eim->cache_entry.h,
482 func.image_alpha_get(data, eim),
483 func.image_colorspace_get(data, eim),
487 case EVAS_COLORSPACE_YCBCR422P601_PL:
488 case EVAS_COLORSPACE_YCBCR422P709_PL:
489 if (image_data != im->cs.data)
494 im->cs.data = image_data;
495 evas_common_image_colorspace_dirty(im);
506 evas_engine_sdl_image_alpha_set(void *data, void *image, int has_alpha)
508 SDL_Engine_Image_Entry *eim = image;
513 if (!eim) return NULL;
515 im = (RGBA_Image *) eim->cache_entry.src;
517 if (eim->cache_entry.src->space != EVAS_COLORSPACE_ARGB8888)
519 im->cache_entry.flags.alpha = 0;
523 eim = (SDL_Engine_Image_Entry *) evas_cache_engine_image_dirty(&eim->cache_entry, 0, 0, eim->cache_entry.w, eim->cache_entry.h);
525 /* FIXME: update SDL_Surface flags */
526 im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
531 evas_engine_sdl_image_border_set(void *data, void *image, int l, int r, int t, int b)
537 evas_engine_sdl_image_border_get(void *data, void *image, int *l, int *r, int *t, int *b)
539 /* FIXME: need to know what evas expect from this call */
543 evas_engine_sdl_image_draw(void *data, void *context, void *surface, void *image,
544 int src_region_x, int src_region_y, int src_region_w, int src_region_h,
545 int dst_region_x, int dst_region_y, int dst_region_w, int dst_region_h,
548 SDL_Engine_Image_Entry *eim = image;
549 SDL_Engine_Image_Entry *dst = surface;
550 RGBA_Draw_Context *dc = (RGBA_Draw_Context*) context;
552 int mustlock_dst = 0;
556 if (eim->cache_entry.src->space == EVAS_COLORSPACE_ARGB8888)
557 evas_cache_engine_image_load_data(&eim->cache_entry);
559 /* Fallback to software method */
560 if (SDL_MUSTLOCK(dst->surface))
563 SDL_LockSurface(dst->surface);
564 _SDL_UPDATE_PIXELS(dst);
567 if (eim->surface && SDL_MUSTLOCK(eim->surface))
570 SDL_LockSurface(eim->surface);
571 _SDL_UPDATE_PIXELS(eim);
574 evas_common_image_colorspace_normalize((RGBA_Image *) eim->cache_entry.src);
577 evas_common_scale_rgba_in_to_out_clip_smooth((RGBA_Image *) eim->cache_entry.src,
578 (RGBA_Image *) dst->cache_entry.src,
580 src_region_x, src_region_y, src_region_w, src_region_h,
581 dst_region_x, dst_region_y, dst_region_w, dst_region_h);
583 evas_common_scale_rgba_in_to_out_clip_sample((RGBA_Image *) eim->cache_entry.src,
584 (RGBA_Image *) dst->cache_entry.src,
586 src_region_x, src_region_y, src_region_w, src_region_h,
587 dst_region_x, dst_region_y, dst_region_w, dst_region_h);
588 evas_common_cpu_end_opt ();
591 SDL_UnlockSurface(eim->surface);
594 SDL_UnlockSurface(dst->surface);
598 evas_engine_sdl_image_cache_flush(void *data)
600 Render_Engine *re = (Render_Engine*) data;
603 size = evas_cache_engine_image_get(re->cache);
604 evas_cache_engine_image_set(re->cache, 0);
605 evas_cache_engine_image_set(re->cache, size);
609 evas_engine_sdl_image_cache_set(void *data, int bytes)
611 Render_Engine *re = (Render_Engine*) data;
613 evas_cache_engine_image_set(re->cache, bytes);
617 evas_engine_sdl_image_cache_get(void *data)
619 Render_Engine *re = (Render_Engine*) data;
621 return evas_cache_engine_image_get(re->cache);
625 evas_engine_sdl_image_comment_get(void *data, void *image, char *key)
627 SDL_Engine_Image_Entry *eim = image;
630 if (!eim) return NULL;
631 im = (RGBA_Image *) eim->cache_entry.src;
633 return im->info.comment;
637 evas_engine_sdl_image_format_get(void *data, void *image)
639 /* FIXME: need to know what evas expect from this call */
644 evas_engine_sdl_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)
646 SDL_Engine_Image_Entry *eim = surface;
649 if (eim->surface && SDL_MUSTLOCK(eim->surface))
652 SDL_LockSurface(eim->surface);
653 _SDL_UPDATE_PIXELS(eim);
656 evas_common_font_draw((RGBA_Image *) eim->cache_entry.src, context, font, x, y, text);
657 evas_common_cpu_end_opt();
660 SDL_UnlockSurface(eim->surface);
664 evas_engine_sdl_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2)
666 SDL_Engine_Image_Entry *eim = surface;
669 if (eim->surface && SDL_MUSTLOCK(eim->surface))
672 SDL_LockSurface(eim->surface);
673 _SDL_UPDATE_PIXELS(eim);
676 evas_common_line_draw((RGBA_Image *) eim->cache_entry.src, context, x1, y1, x2, y2);
677 evas_common_cpu_end_opt();
680 SDL_UnlockSurface(eim->surface);
684 evas_engine_sdl_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h)
686 SDL_Engine_Image_Entry *eim = surface;
687 #if ENGINE_SDL_PRIMITIVE
688 RGBA_Draw_Context *dc = context;
692 #if ENGINE_SDL_PRIMITIVE
693 if (A_VAL(&dc->col.col) != 0x00)
695 if (A_VAL(&dc->col.col) != 0xFF)
698 if (eim->surface && SDL_MUSTLOCK(eim->surface))
701 SDL_LockSurface(eim->surface);
702 _SDL_UPDATE_PIXELS(eim);
705 evas_common_rectangle_draw((RGBA_Image *) eim->cache_entry.src, context, x, y, w, h);
706 evas_common_cpu_end_opt();
709 SDL_UnlockSurface(eim->surface);
710 #if ENGINE_SDL_PRIMITIVE
720 cliprect.x = dc->clip.x;
721 cliprect.y = dc->clip.y;
722 cliprect.w = dc->clip.w;
723 cliprect.h = dc->clip.h;
725 SDL_SetClipRect(eim->surface, &cliprect);
733 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));
736 SDL_SetClipRect(eim->surface, NULL);
743 evas_engine_sdl_polygon_draw(void *data, void *context, void *surface, void *polygon)
745 SDL_Engine_Image_Entry *eim = surface;
748 if (eim->surface && SDL_MUSTLOCK(eim->surface))
751 SDL_LockSurface(eim->surface);
752 _SDL_UPDATE_PIXELS(eim);
755 evas_common_polygon_draw((RGBA_Image *) eim->cache_entry.src, context, polygon);
756 evas_common_cpu_end_opt();
759 SDL_UnlockSurface(eim->surface);
763 evas_engine_sdl_gradient_draw(void *data, void *context, void *surface, void *gradient, int x, int y, int w, int h)
765 SDL_Engine_Image_Entry *eim = surface;
768 if (eim->surface && SDL_MUSTLOCK(eim->surface))
771 SDL_LockSurface(eim->surface);
772 _SDL_UPDATE_PIXELS(eim);
775 evas_common_gradient_draw((RGBA_Image *) eim->cache_entry.src, context, x, y, w, h, gradient);
776 evas_common_cpu_end_opt();
779 SDL_UnlockSurface(eim->surface);
782 EAPI int module_open(Evas_Module *em)
785 /* get whatever engine module we inherit from */
786 if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
787 /* store it for later use */
789 /* now to override methods */
790 #define ORD(f) EVAS_API_OVERRIDE(f, &func, evas_engine_sdl_)
796 ORD(output_tile_size_set);
797 ORD(output_redraws_rect_add);
798 ORD(output_redraws_rect_del);
799 ORD(output_redraws_clear);
800 ORD(output_redraws_next_update_get);
801 ORD(output_redraws_next_update_push);
803 ORD(output_idle_flush);
805 ORD(image_new_from_data);
806 ORD(image_new_from_copied_data);
807 ORD(image_colorspace_set);
808 ORD(image_colorspace_get);
812 ORD(image_dirty_region);
815 ORD(image_alpha_set);
816 ORD(image_alpha_get);
817 ORD(image_border_set);
818 ORD(image_border_get);
820 ORD(image_comment_get);
821 ORD(image_format_get);
822 ORD(image_cache_flush);
823 ORD(image_cache_set);
824 ORD(image_cache_get);
830 /* now advertise out own api */
831 em->functions = (void *)(&func);
835 EAPI void module_close(void)
840 EAPI Evas_Module_Api evas_modapi =
842 EVAS_MODULE_API_VERSION,
843 EVAS_MODULE_TYPE_ENGINE,
848 /* Private routines. */
851 _sdl_output_setup (int w, int h, int fullscreen, int noframe, int alpha, int hwsurface)
853 Render_Engine *re = calloc(1, sizeof(Render_Engine));
854 SDL_Surface *surface;
856 /* if we haven't initialized - init (automatic abort if already done) */
857 evas_common_cpu_init();
858 evas_common_blend_init();
859 evas_common_image_init();
860 evas_common_convert_init();
861 evas_common_scale_init();
862 evas_common_rectangle_init();
863 evas_common_gradient_init();
864 evas_common_polygon_init();
865 evas_common_line_init();
866 evas_common_font_init();
867 evas_common_draw_init();
868 evas_common_tilebuf_init();
873 re->cache = evas_cache_engine_image_init(&_sdl_cache_engine_image_cb, evas_common_image_cache_get());
876 fprintf(stderr, "Evas_Cache_Engine_Image allocation failed!\n");
880 re->tb = evas_common_tilebuf_new(w, h);
881 /* in preliminary tests 16x16 gave highest framerates */
882 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
883 surface = SDL_SetVideoMode(w, h, 32,
884 (hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE)
885 | (fullscreen ? SDL_FULLSCREEN : 0)
886 | (noframe ? SDL_NOFRAME : 0)
887 | (alpha ? SDL_SRCALPHA : 0));
891 fprintf(stderr, "SDL_SetVideoMode [ %i x %i x 32 ] failed.\n", w, h);
895 SDL_SetAlpha(surface, SDL_SRCALPHA | SDL_RLEACCEL, 0);
897 /* We create a "fake" RGBA_Image which points to the SDL surface. Each access
898 * to that surface is wrapped in Lock / Unlock calls whenever the data is
899 * manipulated directly. */
900 re->rgba_engine_image = (SDL_Engine_Image_Entry *) evas_cache_engine_image_engine(re->cache, surface);
901 if (!re->rgba_engine_image)
903 fprintf(stderr, "RGBA_Image allocation from SDL failed\n");
907 SDL_FillRect(surface, NULL, 0);
909 re->flags.alpha = alpha;
910 re->flags.hwsurface = hwsurface;
911 re->flags.fullscreen = fullscreen;
912 re->flags.noframe = noframe;
916 static Engine_Image_Entry*
917 _sdl_image_alloc(void)
919 SDL_Engine_Image_Entry *new;
921 new = calloc(1, sizeof (SDL_Engine_Image_Entry));
923 return (Engine_Image_Entry *) new;
927 _sdl_image_delete(Engine_Image_Entry *eim)
933 _sdl_image_constructor(Engine_Image_Entry *ie, void *data)
935 SDL_Surface *sdl = NULL;
936 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) ie;
939 im = (RGBA_Image *) ie->src;
943 evas_cache_image_load_data(&im->cache_entry);
947 /* FIXME: Take care of CSPACE */
948 sdl = SDL_CreateRGBSurfaceFrom(im->image.data,
951 RMASK, GMASK, BMASK, AMASK);
953 eim->flags.engine_surface = 0;
961 _sdl_image_destructor(Engine_Image_Entry *eie)
963 SDL_Engine_Image_Entry *seie = (SDL_Engine_Image_Entry *) eie;
965 if (seie->surface && !seie->flags.engine_surface)
966 SDL_FreeSurface(seie->surface);
967 seie->surface = NULL;
971 _sdl_image_dirty(Engine_Image_Entry *dst, const Engine_Image_Entry *src)
973 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) dst;
974 SDL_Surface *sdl = NULL;
977 im = (RGBA_Image *) dst->src;
979 /* FIXME: Take care of CSPACE */
980 sdl = SDL_CreateRGBSurfaceFrom(im->image.data,
983 0xff0000, 0xff00, 0xff, 0xff000000);
985 eim->flags.engine_surface = 0;
991 _sdl_image_update_data(Engine_Image_Entry *dst, void* engine_data)
993 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) dst;
994 SDL_Surface *sdl = NULL;
997 im = (RGBA_Image *) dst->src;
1005 im->image.data = sdl->pixels;
1006 im->image.no_free = 1;
1007 im->cache_entry.flags.alpha = 0;
1008 dst->src->w = sdl->w;
1009 dst->src->h = sdl->h;
1016 /* FIXME: Take care of CSPACE */
1017 SDL_FreeSurface(eim->surface);
1018 sdl = SDL_CreateRGBSurfaceFrom(im->image.data,
1021 RMASK, GMASK, BMASK, AMASK);
1030 _sdl_image_size_set(Engine_Image_Entry *dst, const Engine_Image_Entry *src)
1032 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) dst;
1036 im = (RGBA_Image *) dst->src;
1038 /* FIXME: handle im == NULL */
1039 sdl = SDL_CreateRGBSurfaceFrom(im->image.data,
1042 RMASK, GMASK, BMASK, AMASK);
1050 _sdl_image_load(Engine_Image_Entry *eim, const Image_Entry *ie_im)
1052 SDL_Engine_Image_Entry *load = (SDL_Engine_Image_Entry *) eim;
1059 im = (RGBA_Image *) ie_im;
1061 sdl = SDL_CreateRGBSurfaceFrom(im->image.data,
1064 RMASK, GMASK, BMASK, AMASK);
1065 load->surface = sdl;
1070 _sdl_image_mem_size_get(Engine_Image_Entry *eim)
1072 SDL_Engine_Image_Entry *seie = (SDL_Engine_Image_Entry *) eim;
1075 /* FIXME: Count surface size. */
1077 size = sizeof (SDL_Surface) + sizeof (SDL_PixelFormat);
1084 _sdl_image_debug(const char* context, Engine_Image_Entry* eie)
1086 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) eie;
1088 printf ("*** %s image (%p) ***\n", context, eim);
1091 printf ("* W: %i\n* H: %i\n* R: %i\n", eim->cache_entry.w, eim->cache_entry.h, eim->cache_entry.references);
1092 if (eim->cache_entry.src)
1093 printf ("* Pixels: %p\n* SDL Surface: %p\n",((RGBA_Image*) eim->cache_entry.src)->image.data, eim->surface);
1095 printf ("* Surface->pixels: %p\n", eim->surface->pixels);
1096 printf ("* Key: %s\n", eim->cache_entry.cache_key);
1097 printf ("* Reference: %i\n", eim->cache_entry.references);
1099 printf ("*** ***\n");