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)
233 evas_cache_engine_image_drop(&re->soft16_engine_image->cache_entry);
234 if (re->cache) evas_cache_engine_image_shutdown(re->cache);
236 if (re->update_rects)
237 free(re->update_rects);
240 evas_common_font_shutdown();
241 evas_common_image_shutdown();
242 evas_common_soft16_image_shutdown();
244 SDL_QuitSubSystem(SDL_INIT_VIDEO);
248 evas_engine_sdl16_output_resize(void *data, int w, int h)
250 Render_Engine *re = data;
251 SDL_Surface *surface;
253 if ((re->tb->outbuf_w == w) && (re->tb->outbuf_h == h)) return;
255 evas_cache_engine_image_drop(&re->soft16_engine_image->cache_entry);
257 evas_common_tilebuf_free(re->tb);
260 re->tb = evas_common_tilebuf_new(w, h);
262 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
264 surface = SDL_SetVideoMode(w, h, 16,
265 (re->flags.hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE)
266 | (re->flags.fullscreen ? SDL_FULLSCREEN : 0)
267 | (re->flags.noframe ? SDL_NOFRAME : 0));
270 ERR("Unable to change the resolution to : %ix%i", w, h);
273 re->soft16_engine_image = (SDL_Engine_Image_Entry *) evas_cache_engine_image_engine(re->cache, surface);
274 if (!re->soft16_engine_image)
276 ERR("RGBA_Image allocation from SDL failed");
280 SDL_FillRect(surface, NULL, 0);
284 evas_cache_image_drop(&re->tmp_out->cache_entry);
290 evas_engine_sdl16_output_tile_size_set(void *data, int w, int h)
294 re = (Render_Engine *)data;
295 evas_common_tilebuf_set_tile_size(re->tb, w, h);
299 evas_engine_sdl16_output_redraws_rect_add(void *data, int x, int y, int w, int h)
303 re = (Render_Engine *)data;
304 evas_common_tilebuf_add_redraw(re->tb, x, y, w, h);
308 evas_engine_sdl16_output_redraws_rect_del(void *data, int x, int y, int w, int h)
312 re = (Render_Engine *)data;
313 evas_common_tilebuf_del_redraw(re->tb, x, y, w, h);
317 evas_engine_sdl16_output_redraws_clear(void *data)
321 re = (Render_Engine *)data;
322 evas_common_tilebuf_clear(re->tb);
326 evas_engine_sdl16_output_redraws_next_update_get(void *data,
327 int *x, int *y, int *w, int *h,
328 int *cx, int *cy, int *cw, int *ch)
330 Render_Engine *re = data;
331 Tilebuf_Rect *tb_rect;
341 re->rects = evas_common_tilebuf_get_render_rects(re->tb);
342 re->cur_rect = re->rects;
343 if (re->rot != 0) _tmp_out_alloc(re); /* grows if required */
348 if (re->rects) evas_common_tilebuf_free_render_rects(re->rects);
353 tb_rect = re->cur_rect;
354 *cx = *x = tb_rect->x;
355 *cy = *y = tb_rect->y;
356 *cw = *w = tb_rect->w;
357 *ch = *h = tb_rect->h;
358 re->cur_rect = (Tilebuf_Rect *)((EINA_INLIST_GET(re->cur_rect))->next);
361 evas_common_tilebuf_free_render_rects(re->rects);
377 /* Return the "fake" surface so it is passed to the drawing routines. */
378 return re->soft16_engine_image;
382 _blit_rot_90(Soft16_Image *dst, const Soft16_Image *src,
383 int out_x, int out_y, int w, int h)
389 dp = dst->pixels + (out_x +
390 (w + out_y - 1) * dst->stride);
392 for (y = 0; y < h; y++)
394 DATA16 *dp_itr, *sp_itr;
399 for (x = 0; x < w; x++)
404 dp_itr -= dst->stride;
412 _blit_rot_180(Soft16_Image *dst, const Soft16_Image *src,
413 int out_x, int out_y, int w, int h)
419 dp = dst->pixels + ((w + out_x - 1) +
420 (h + out_y - 1) * dst->stride);
422 for (y = 0; y < h; y++)
424 DATA16 *dp_itr, *sp_itr;
429 for (x = 0; x < w; x++)
442 _blit_rot_270(Soft16_Image *dst, const Soft16_Image *src,
443 int out_x, int out_y, int w, int h)
449 dp = dst->pixels + ((h + out_x - 1) +
450 out_y * dst->stride);
452 for (y = 0; y < h; y++)
454 DATA16 *dp_itr, *sp_itr;
459 for (x = 0; x < w; x++)
464 dp_itr += dst->stride;
472 _tmp_out_process(Render_Engine *re, int out_x, int out_y, int w, int h)
476 d = (Soft16_Image *) re->soft16_engine_image->cache_entry.src;
479 if ((w < 1) || (h < 1) ||
480 (out_x >= (int)d->cache_entry.w) || (out_y >= (int)d->cache_entry.h))
484 _blit_rot_90(d, s, out_x, out_y, w, h);
485 else if (re->rot == 180)
486 _blit_rot_180(d, s, out_x, out_y, w, h);
487 else if (re->rot == 270)
488 _blit_rot_270(d, s, out_x, out_y, w, h);
492 evas_engine_sdl16_output_redraws_next_update_push(void *data, void *surface __UNUSED__,
493 int x, int y, int w, int h)
495 Render_Engine *re = data;
498 if (re->update_rects_count + 1 > re->update_rects_limit)
500 re->update_rects_limit += 8;
501 re->update_rects = realloc(re->update_rects, sizeof (SDL_Rect) * re->update_rects_limit);
515 rect.y = re->w - w - x;
520 rect.x = re->w - w - x;
521 rect.y = re->h - h - y;
524 rect.x = re->h - h - y;
533 re->update_rects[re->update_rects_count] = rect;
536 _tmp_out_process(re, rect.x, rect.y, w, h);
538 ++re->update_rects_count;
540 evas_common_cpu_end_opt();
544 evas_engine_sdl16_output_flush(void *data)
546 Render_Engine *re = data;
548 if (re->update_rects_count > 0)
549 SDL_UpdateRects(re->soft16_engine_image->surface, re->update_rects_count, re->update_rects);
551 re->update_rects_count = 0;
555 evas_engine_sdl16_output_idle_flush(void *data)
559 re = (Render_Engine *)data;
562 evas_cache_image_drop(&re->tmp_out->cache_entry);
568 evas_engine_sdl16_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
570 Render_Engine* re = (Render_Engine*) data;;
573 return evas_cache_engine_image_request(re->cache, file, key, lo, NULL, error);
577 evas_engine_sdl16_image_alpha_get(void *data __UNUSED__, void *image)
579 SDL_Engine_Image_Entry *eim = image;
583 im = (Soft16_Image *) eim->cache_entry.src;
584 switch (eim->cache_entry.src->space)
586 case EVAS_COLORSPACE_ARGB8888:
587 if (im->cache_entry.flags.alpha) return 1;
595 evas_engine_sdl16_image_size_get(void *data __UNUSED__, void *image, int *w, int *h)
597 SDL_Engine_Image_Entry *eim;
600 if (w) *w = eim->cache_entry.src->w;
601 if (h) *h = eim->cache_entry.src->h;
605 evas_engine_sdl16_image_colorspace_get(void *data __UNUSED__, void *image __UNUSED__)
607 SDL_Engine_Image_Entry *eim = image;
609 if (!eim) return EVAS_COLORSPACE_RGB565_A5P;
610 return eim->cache_entry.src->space;
614 evas_engine_sdl16_image_colorspace_set(void *data __UNUSED__, void *image __UNUSED__, int cspace __UNUSED__)
616 SDL_Engine_Image_Entry *eim = image;
619 if (eim->cache_entry.src->space == cspace) return;
621 evas_cache_engine_image_colorspace(&eim->cache_entry, cspace, NULL);
625 evas_engine_sdl16_image_new_from_copied_data(void *data,
628 int alpha, int cspace)
630 Render_Engine *re = data;
632 if (cspace != EVAS_COLORSPACE_RGB565_A5P)
634 WRN("Unsupported colorspace %d in %s() (%s:%d)",
635 cspace, __FUNCTION__, __FILE__, __LINE__);
639 WRN("s image_data: %p", image_data);
641 return evas_cache_engine_image_copied_data(re->cache,
644 alpha, cspace, NULL);
648 evas_engine_sdl16_image_new_from_data(void *data, int w, int h, DATA32* image_data, int alpha, int cspace)
650 Render_Engine *re = data;
652 if (cspace != EVAS_COLORSPACE_RGB565_A5P)
654 WRN("Unsupported colorspace %d in %s() (%s:%d)",
655 cspace, __FUNCTION__, __FILE__, __LINE__);
659 return evas_cache_engine_image_data(re->cache,
662 alpha, cspace, NULL);
666 evas_engine_sdl16_image_free(void *data __UNUSED__, void *image)
668 SDL_Engine_Image_Entry *eim = image;
670 evas_cache_engine_image_drop(&eim->cache_entry);
674 evas_engine_sdl16_image_size_set(void *data __UNUSED__, void *image, int w, int h)
676 SDL_Engine_Image_Entry *eim = image;
678 return evas_cache_engine_image_size_set(&eim->cache_entry, w, h);
682 evas_engine_sdl16_image_dirty_region(void *data __UNUSED__,
684 int x, int y, int w, int h)
686 SDL_Engine_Image_Entry *eim = image;
688 return evas_cache_engine_image_dirty(&eim->cache_entry, x, y, w, h);
692 evas_engine_sdl16_image_data_get(void *data __UNUSED__, void *image,
693 int to_write, DATA32** image_data, int *err)
695 SDL_Engine_Image_Entry *eim = image;
702 if (err) *err = EVAS_LOAD_ERROR_GENERIC;
705 im = (Soft16_Image *) eim->cache_entry.src;
708 eim = (SDL_Engine_Image_Entry *) evas_cache_engine_image_dirty(&eim->cache_entry,
709 0, 0, eim->cache_entry.src->w, eim->cache_entry.src->h);
711 error = evas_cache_image_load_data(&im->cache_entry);
712 /* FIXME: Handle colorspace conversion correctly. */
713 if (image_data) *image_data = (DATA32 *) im->pixels;
715 if (err) *err = error;
720 evas_engine_sdl16_image_data_put(void *data, void *image, DATA32* image_data)
722 SDL_Engine_Image_Entry *eim = image;
723 SDL_Engine_Image_Entry *eim_new;
724 Render_Engine *re = data;
727 if (!eim) return NULL;
728 im = (Soft16_Image *) eim->cache_entry.src;
730 /* FIXME: Handle colorspace conversion correctly. */
731 if ((DATA16 *) image_data == im->pixels) return eim;
733 eim_new = (SDL_Engine_Image_Entry *) evas_cache_engine_image_data(re->cache,
734 eim->cache_entry.w, eim->cache_entry.h,
736 func.image_alpha_get(data, eim),
737 func.image_colorspace_get(data, eim),
739 evas_cache_engine_image_drop(&eim->cache_entry);
745 evas_engine_sdl16_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
747 SDL_Engine_Image_Entry *eim = image;
751 im = (Soft16_Image *) eim->cache_entry.src;
753 evas_cache_image_preload_data(&im->cache_entry, target);
757 evas_engine_sdl16_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
759 SDL_Engine_Image_Entry *eim = image;
763 im = (Soft16_Image *) eim->cache_entry.src;
765 evas_cache_image_preload_cancel(&im->cache_entry, target);
769 evas_engine_sdl16_image_alpha_set(void *data __UNUSED__, void *image, int has_alpha)
771 SDL_Engine_Image_Entry *eim = image;
774 if (!eim) return NULL;
776 im = (Soft16_Image *) eim->cache_entry.src;
778 if (im->cache_entry.flags.alpha == has_alpha) return eim;
780 //eim = (SDL_Engine_Image_Entry *) evas_cache_engine_image_alone(&eim->cache_entry, NULL);
781 //im = (Soft16_Image *) eim->cache_entry.src;
783 im->cache_entry.flags.alpha = has_alpha;
784 eim = (SDL_Engine_Image_Entry *) evas_cache_engine_image_dirty(&eim->cache_entry, 0, 0, eim->cache_entry.w, eim->cache_entry.h);
790 evas_engine_sdl16_image_border_set(void *data __UNUSED__, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
796 evas_engine_sdl16_image_border_get(void *data __UNUSED__, void *image __UNUSED__, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
798 /* FIXME: need to know what evas expect from this call */
802 evas_engine_sdl16_image_draw(void *data __UNUSED__, void *context, void *surface, void *image,
803 int src_region_x, int src_region_y, int src_region_w, int src_region_h,
804 int dst_region_x, int dst_region_y, int dst_region_w, int dst_region_h,
807 SDL_Engine_Image_Entry *eim = image;
808 SDL_Engine_Image_Entry *dst = surface;
810 int mustlock_dst = 0;
812 evas_cache_engine_image_load_data(&eim->cache_entry);
814 /* Fallback to software method */
815 if (SDL_MUSTLOCK(dst->surface))
818 SDL_LockSurface(dst->surface);
819 _SDL_UPDATE_PIXELS(dst);
822 if (eim->surface && SDL_MUSTLOCK(eim->surface))
825 SDL_LockSurface(eim->surface);
826 _SDL_UPDATE_PIXELS(eim);
829 evas_common_soft16_image_draw((Soft16_Image *) eim->cache_entry.src,
830 (Soft16_Image *) dst->cache_entry.src,
832 src_region_x, src_region_y, src_region_w, src_region_h,
833 dst_region_x, dst_region_y, dst_region_w, dst_region_h,
836 evas_common_cpu_end_opt ();
838 SDL_UnlockSurface(eim->surface);
841 SDL_UnlockSurface(dst->surface);
845 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__)
850 evas_engine_sdl16_image_scale_hint_set(void *data __UNUSED__, void *image __UNUSED__, int hint __UNUSED__)
855 evas_engine_sdl16_image_scale_hint_get(void *data __UNUSED__, void *image __UNUSED__)
857 return EVAS_IMAGE_SCALE_HINT_NONE;
862 evas_engine_sdl16_image_cache_flush(void *data)
864 Render_Engine *re = (Render_Engine*) data;
867 size = evas_cache_engine_image_get(re->cache);
868 evas_cache_engine_image_set(re->cache, 0);
869 evas_cache_engine_image_set(re->cache, size);
873 evas_engine_sdl16_image_cache_set(void *data, int bytes)
875 Render_Engine *re = (Render_Engine*) data;
877 evas_cache_engine_image_set(re->cache, bytes);
881 evas_engine_sdl16_image_cache_get(void *data)
883 Render_Engine *re = (Render_Engine*) data;
885 return evas_cache_engine_image_get(re->cache);
889 evas_engine_sdl16_image_comment_get(void *data __UNUSED__, void *image __UNUSED__, char *key __UNUSED__)
895 evas_engine_sdl16_image_format_get(void *data __UNUSED__, void *image __UNUSED__)
897 /* FIXME: need to know what evas expect from this call */
902 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)
904 static RGBA_Image *im = NULL;
905 SDL_Engine_Image_Entry *eim = surface;
906 Soft16_Image *dst = (Soft16_Image *) eim->cache_entry.src;
909 if (eim->surface && SDL_MUSTLOCK(eim->surface))
912 SDL_LockSurface(eim->surface);
913 _SDL_UPDATE_PIXELS(eim);
915 evas_common_draw_context_font_ext_set(context,
917 evas_common_soft16_font_glyph_new,
918 evas_common_soft16_font_glyph_free,
919 evas_common_soft16_font_glyph_draw);
920 evas_common_font_draw((RGBA_Image *) eim->cache_entry.src, context, font, x, y, intl_props);
921 evas_common_draw_context_font_ext_set(context,
928 SDL_UnlockSurface(eim->surface);
932 evas_engine_sdl16_line_draw(void *data __UNUSED__, void *context, void *surface, int x1, int y1, int x2, int y2)
934 SDL_Engine_Image_Entry *eim = surface;
937 if (eim->surface && SDL_MUSTLOCK(eim->surface))
940 SDL_LockSurface(eim->surface);
941 _SDL_UPDATE_PIXELS(eim);
944 evas_common_soft16_line_draw((Soft16_Image *) eim->cache_entry.src,
947 evas_common_cpu_end_opt();
950 SDL_UnlockSurface(eim->surface);
954 evas_engine_sdl16_rectangle_draw(void *data __UNUSED__, void *context, void *surface, int x, int y, int w, int h)
956 SDL_Engine_Image_Entry *eim = surface;
957 #if ENGINE_SDL_PRIMITIVE
958 RGBA_Draw_Context *dc = context;
963 #if ENGINE_SDL_PRIMITIVE
964 if (A_VAL(&dc->col.col) != 0x00)
966 if (A_VAL(&dc->col.col) != 0xFF)
969 if (eim->surface && SDL_MUSTLOCK(eim->surface))
972 SDL_LockSurface(eim->surface);
973 _SDL_UPDATE_PIXELS(eim);
976 im = (Soft16_Image *) eim->cache_entry.src;
978 evas_common_soft16_rectangle_draw(im, context, x, y, w, h);
979 evas_common_cpu_end_opt();
982 SDL_UnlockSurface(eim->surface);
983 #if ENGINE_SDL_PRIMITIVE
993 cliprect.x = dc->clip.x;
994 cliprect.y = dc->clip.y;
995 cliprect.w = dc->clip.w;
996 cliprect.h = dc->clip.h;
998 SDL_SetClipRect(eim->surface, &cliprect);
1006 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));
1009 SDL_SetClipRect(eim->surface, NULL);
1016 evas_engine_sdl16_polygon_draw(void *data __UNUSED__, void *context, void *surface, void *polygon, int x, int y)
1018 SDL_Engine_Image_Entry *eim = surface;
1019 int mustlock_im = 0;
1021 if (eim->surface && SDL_MUSTLOCK(eim->surface))
1024 SDL_LockSurface(eim->surface);
1025 _SDL_UPDATE_PIXELS(eim);
1028 evas_common_soft16_polygon_draw((Soft16_Image *) eim->cache_entry.src, context, polygon, x, y);
1029 evas_common_cpu_end_opt();
1032 SDL_UnlockSurface(eim->surface);
1036 evas_engine_sdl16_image_stride_get(void *data __UNUSED__, void *image, int *stride)
1038 SDL_Engine_Image_Entry *eim = image;
1040 if (stride) *stride = 0;
1042 if (stride) *stride = ((Soft16_Image*) eim->cache_entry.src)->stride;
1046 evas_engine_sdl16_canvas_alpha_get(void *data __UNUSED__, void *context __UNUSED__)
1051 /* module advertising code */
1053 module_open(Evas_Module *em)
1056 /* get whatever engine module we inherit from */
1057 if (!_evas_module_engine_inherit(&pfunc, "software_16")) return 0;
1058 _evas_engine_soft16_sdl_log_dom = eina_log_domain_register
1059 ("evas-software_16_sdl", EVAS_DEFAULT_LOG_COLOR);
1060 if (_evas_engine_soft16_sdl_log_dom < 0)
1062 EINA_LOG_ERR("Can not create a module log domain.");
1066 /* store it for later use */
1068 /* now to override methods */
1069 #define ORD(f) EVAS_API_OVERRIDE(f, &func, evas_engine_sdl16_)
1073 ORD(canvas_alpha_get);
1076 ORD(output_tile_size_set);
1077 ORD(output_redraws_rect_add);
1078 ORD(output_redraws_rect_del);
1079 ORD(output_redraws_clear);
1080 ORD(output_redraws_next_update_get);
1081 ORD(output_redraws_next_update_push);
1083 ORD(output_idle_flush);
1085 ORD(image_alpha_get);
1086 ORD(image_size_get);
1087 ORD(image_colorspace_get);
1088 ORD(image_colorspace_set);
1089 ORD(image_new_from_copied_data);
1090 ORD(image_new_from_data);
1092 ORD(image_size_set);
1093 ORD(image_dirty_region);
1094 ORD(image_data_get);
1095 ORD(image_data_put);
1096 ORD(image_data_preload_request);
1097 ORD(image_data_preload_cancel);
1098 ORD(image_alpha_set);
1099 ORD(image_border_set);
1100 ORD(image_border_get);
1102 ORD(image_map_draw);
1103 ORD(image_cache_flush);
1104 ORD(image_cache_set);
1105 ORD(image_cache_get);
1106 ORD(image_comment_get);
1107 ORD(image_format_get);
1108 ORD(image_stride_get);
1111 ORD(rectangle_draw);
1114 ORD(image_scale_hint_set);
1115 ORD(image_scale_hint_get);
1117 /* now advertise out own api */
1118 em->functions = (void *)(&func);
1123 module_close(Evas_Module *em __UNUSED__)
1125 eina_log_domain_unregister(_evas_engine_soft16_sdl_log_dom);
1128 static Evas_Module_Api evas_modapi =
1130 EVAS_MODULE_API_VERSION,
1139 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, software_16_sdl);
1141 #ifndef EVAS_STATIC_BUILD_SOFTWARE_SDL
1142 EVAS_EINA_MODULE_DEFINE(engine, software_16_sdl);
1145 static Engine_Image_Entry*
1146 _sdl16_image_alloc(void)
1148 SDL_Engine_Image_Entry *new;
1150 new = calloc(1, sizeof (SDL_Engine_Image_Entry));
1152 return (Engine_Image_Entry *) new;
1156 _sdl16_image_delete(Engine_Image_Entry *eim)
1162 _sdl16_image_constructor(Engine_Image_Entry *ie, void* data __UNUSED__)
1164 SDL_Surface *sdl = NULL;
1165 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) ie;
1168 im = (Soft16_Image *) ie->src;
1172 evas_cache_image_load_data(&im->cache_entry);
1176 /* FIXME: Take care of CSPACE */
1177 sdl = SDL_CreateRGBSurfaceFrom(im->pixels,
1180 RMASK565, GMASK565, BMASK565, AMASK565);
1182 eim->flags.engine_surface = 0;
1186 return EVAS_LOAD_ERROR_NONE;
1190 _sdl16_image_destructor(Engine_Image_Entry *eim)
1192 SDL_Engine_Image_Entry *seie = (SDL_Engine_Image_Entry *) eim;
1194 if (seie->surface && !seie->flags.engine_surface)
1195 SDL_FreeSurface(seie->surface);
1196 seie->surface = NULL;
1200 _sdl16_image_dirty_region(Engine_Image_Entry *eim, unsigned int x, unsigned int y, unsigned int w, unsigned int h)
1202 SDL_Engine_Image_Entry *dst;
1205 dst = (SDL_Engine_Image_Entry *) eim;
1207 SDL_UpdateRect(dst->surface, x, y, w, h);
1209 im = (RGBA_Image *)eim->src;
1210 im->flags |= RGBA_IMAGE_IS_DIRTY;
1214 _sdl16_image_dirty(Engine_Image_Entry *dst, const Engine_Image_Entry *src __UNUSED__)
1216 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) dst;
1217 SDL_Surface *sdl = NULL;
1220 im = (Soft16_Image *) dst->src;
1222 /* FIXME: Take care of CSPACE */
1223 sdl = SDL_CreateRGBSurfaceFrom(im->pixels,
1226 RMASK565, GMASK565, BMASK565, AMASK565);
1228 eim->flags.engine_surface = 0;
1234 _sdl16_image_size_set(Engine_Image_Entry *dst, const Engine_Image_Entry *src __UNUSED__)
1236 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) dst;
1240 im = (Soft16_Image *) dst->src;
1242 /* FIXME: handle im == NULL */
1243 sdl = SDL_CreateRGBSurfaceFrom(im->pixels,
1246 RMASK565, GMASK565, BMASK565, AMASK565);
1254 _sdl16_image_update_data(Engine_Image_Entry* dst, void* engine_data)
1256 SDL_Engine_Image_Entry *eim = (SDL_Engine_Image_Entry *) dst;
1257 SDL_Surface *sdl = NULL;
1260 im = (Soft16_Image *) dst->src;
1268 im->pixels = sdl->pixels;
1269 im->stride = sdl->pitch / 2;
1270 im->flags.free_pixels = 0;
1271 /* im->alpha = calloc(1, sizeof (DATA8) * _calc_stride(sdl->w) * sdl->h); */
1272 /* im->flags.free_alpha = 0; */
1273 /* im->flags.have_alpha = 1; */
1275 im->flags.free_alpha = 0;
1276 im->cache_entry.flags.alpha = 0;
1278 dst->src->w = sdl->w;
1279 dst->src->h = sdl->h;
1286 SDL_FreeSurface(eim->surface);
1287 /* FIXME: Take care of CSPACE */
1288 sdl = SDL_CreateRGBSurfaceFrom(im->pixels,
1291 RMASK565, GMASK565, BMASK565, AMASK565);
1300 _sdl16_image_load(Engine_Image_Entry *eim, const Image_Entry* ie_im)
1302 SDL_Engine_Image_Entry *load = (SDL_Engine_Image_Entry *) eim;
1309 im = (Soft16_Image *) ie_im;
1311 sdl = SDL_CreateRGBSurfaceFrom(im->pixels,
1314 RMASK565, GMASK565, BMASK565, AMASK565);
1315 load->surface = sdl;
1320 _sdl16_image_mem_size_get(Engine_Image_Entry *eim)
1322 SDL_Engine_Image_Entry *seie = (SDL_Engine_Image_Entry *) eim;
1325 /* FIXME: Count surface size. */
1327 size = sizeof (SDL_Surface) + sizeof (SDL_PixelFormat);
1334 _sdl16_image_debug(const char* context, Engine_Image_Entry* im)