evas_object_image Add Animation gif feature
[framework/uifw/evas.git] / src / modules / engines / software_generic / evas_engine.c
1 #include "evas_common.h" /* Also includes international specific stuff */
2 #include "evas_private.h"
3
4 /*
5  *****
6  **
7  ** ENGINE ROUTINES
8  **
9  *****
10  */
11 static int cpunum = 0;
12 static int _evas_soft_gen_log_dom = -1;
13
14 static void
15 eng_output_dump(void *data __UNUSED__)
16 {
17    evas_common_image_image_all_unload();
18    evas_common_font_font_all_unload();
19 }
20
21 static void *
22 eng_context_new(void *data __UNUSED__)
23 {
24    return evas_common_draw_context_new();
25 }
26
27 static void
28 eng_context_free(void *data __UNUSED__, void *context)
29 {
30    evas_common_draw_context_free(context);
31 }
32
33 static void
34 eng_context_clip_set(void *data __UNUSED__, void *context, int x, int y, int w, int h)
35 {
36    evas_common_draw_context_set_clip(context, x, y, w, h);
37 }
38
39 static void
40 eng_context_clip_clip(void *data __UNUSED__, void *context, int x, int y, int w, int h)
41 {
42    evas_common_draw_context_clip_clip(context, x, y, w, h);
43 }
44
45 static void
46 eng_context_clip_unset(void *data __UNUSED__, void *context)
47 {
48    evas_common_draw_context_unset_clip(context);
49 }
50
51 static int
52 eng_context_clip_get(void *data __UNUSED__, void *context, int *x, int *y, int *w, int *h)
53 {
54    *x = ((RGBA_Draw_Context *)context)->clip.x;
55    *y = ((RGBA_Draw_Context *)context)->clip.y;
56    *w = ((RGBA_Draw_Context *)context)->clip.w;
57    *h = ((RGBA_Draw_Context *)context)->clip.h;
58    return ((RGBA_Draw_Context *)context)->clip.use;
59 }
60
61 static void
62 eng_context_color_set(void *data __UNUSED__, void *context, int r, int g, int b, int a)
63 {
64    evas_common_draw_context_set_color(context, r, g, b, a);
65 }
66
67 static int
68 eng_context_color_get(void *data __UNUSED__, void *context, int *r, int *g, int *b, int *a)
69 {
70    *r = (int)(R_VAL(&((RGBA_Draw_Context *)context)->col.col));
71    *g = (int)(G_VAL(&((RGBA_Draw_Context *)context)->col.col));
72    *b = (int)(B_VAL(&((RGBA_Draw_Context *)context)->col.col));
73    *a = (int)(A_VAL(&((RGBA_Draw_Context *)context)->col.col));
74    return 1;
75 }
76
77 static void
78 eng_context_multiplier_set(void *data __UNUSED__, void *context, int r, int g, int b, int a)
79 {
80    evas_common_draw_context_set_multiplier(context, r, g, b, a);
81 }
82
83 static void
84 eng_context_multiplier_unset(void *data __UNUSED__, void *context)
85 {
86    evas_common_draw_context_unset_multiplier(context);
87 }
88
89 static int
90 eng_context_multiplier_get(void *data __UNUSED__, void *context, int *r, int *g, int *b, int *a)
91 {
92    *r = (int)(R_VAL(&((RGBA_Draw_Context *)context)->mul.col));
93    *g = (int)(G_VAL(&((RGBA_Draw_Context *)context)->mul.col));
94    *b = (int)(B_VAL(&((RGBA_Draw_Context *)context)->mul.col));
95    *a = (int)(A_VAL(&((RGBA_Draw_Context *)context)->mul.col));
96    return ((RGBA_Draw_Context *)context)->mul.use;
97 }
98
99 static void
100 eng_context_mask_set(void *data __UNUSED__, void *context, void *mask, int x, int y, int w, int h)
101 {
102    evas_common_draw_context_set_mask(context, mask, x, y, w, h);
103 }
104
105 static void
106 eng_context_mask_unset(void *data __UNUSED__, void *context)
107 {
108    evas_common_draw_context_unset_mask(context);
109 }
110 /*
111 static void *
112 eng_context_mask_get(void *data __UNUSED__, void *context)
113 {
114    return ((RGBA_Draw_Context *)context)->mask.mask;
115 }
116 */
117
118 static void
119 eng_context_cutout_add(void *data __UNUSED__, void *context, int x, int y, int w, int h)
120 {
121    evas_common_draw_context_add_cutout(context, x, y, w, h);
122 }
123
124 static void
125 eng_context_cutout_clear(void *data __UNUSED__, void *context)
126 {
127    evas_common_draw_context_clear_cutouts(context);
128 }
129
130 static void
131 eng_context_anti_alias_set(void *data __UNUSED__, void *context, unsigned char aa)
132 {
133    evas_common_draw_context_set_anti_alias(context, aa);
134 }
135
136 static unsigned char
137 eng_context_anti_alias_get(void *data __UNUSED__, void *context)
138 {
139    return ((RGBA_Draw_Context *)context)->anti_alias;
140 }
141
142 static void
143 eng_context_color_interpolation_set(void *data __UNUSED__, void *context, int color_space)
144 {
145    evas_common_draw_context_set_color_interpolation(context, color_space);
146 }
147
148 static int
149 eng_context_color_interpolation_get(void *data __UNUSED__, void *context)
150 {
151    return ((RGBA_Draw_Context *)context)->interpolation.color_space;
152 }
153
154 static void
155 eng_context_render_op_set(void *data __UNUSED__, void *context, int op)
156 {
157    evas_common_draw_context_set_render_op(context, op);
158 }
159
160 static int
161 eng_context_render_op_get(void *data __UNUSED__, void *context)
162 {
163    return ((RGBA_Draw_Context *)context)->render_op;
164 }
165
166
167
168 static void
169 eng_rectangle_draw(void *data __UNUSED__, void *context, void *surface, int x, int y, int w, int h)
170 {
171 #ifdef BUILD_PIPE_RENDER
172    if ((cpunum > 1)
173 #ifdef EVAS_FRAME_QUEUING
174         && evas_common_frameq_enabled()
175 #endif
176         )
177      evas_common_pipe_rectangle_draw(surface, context, x, y, w, h);
178    else
179 #endif
180      {
181         evas_common_rectangle_draw(surface, context, x, y, w, h);
182         evas_common_cpu_end_opt();
183      }
184 }
185
186 static void
187 eng_line_draw(void *data __UNUSED__, void *context, void *surface, int x1, int y1, int x2, int y2)
188 {
189 #ifdef BUILD_PIPE_RENDER
190    if ((cpunum > 1)
191  #ifdef EVAS_FRAME_QUEUING
192         && evas_common_frameq_enabled()
193 #endif
194         )
195     evas_common_pipe_line_draw(surface, context, x1, y1, x2, y2);
196    else
197 #endif   
198      {
199         evas_common_line_draw(surface, context, x1, y1, x2, y2);
200         evas_common_cpu_end_opt();
201      }
202 }
203
204 static void *
205 eng_polygon_point_add(void *data __UNUSED__, void *context __UNUSED__, void *polygon, int x, int y)
206 {
207    return evas_common_polygon_point_add(polygon, x, y);
208 }
209
210 static void *
211 eng_polygon_points_clear(void *data __UNUSED__, void *context __UNUSED__, void *polygon)
212 {
213    return evas_common_polygon_points_clear(polygon);
214 }
215
216 static void
217 eng_polygon_draw(void *data __UNUSED__, void *context, void *surface, void *polygon, int x, int y)
218 {
219 #ifdef BUILD_PIPE_RENDER
220    if ((cpunum > 1)
221 #ifdef EVAS_FRAME_QUEUING
222         && evas_common_frameq_enabled()
223 #endif
224         )
225      evas_common_pipe_poly_draw(surface, context, polygon, x, y);
226    else
227 #endif
228      {
229         evas_common_polygon_draw(surface, context, polygon, x, y);
230         evas_common_cpu_end_opt();
231      }
232 }
233
234 static int
235 eng_image_alpha_get(void *data __UNUSED__, void *image)
236 {
237    Image_Entry *im;
238
239    if (!image) return 1;
240    im = image;
241    switch (im->space)
242      {
243       case EVAS_COLORSPACE_ARGB8888:
244         if (im->flags.alpha) return 1;
245       default:
246         break;
247      }
248    return 0;
249 }
250
251 static int
252 eng_image_colorspace_get(void *data __UNUSED__, void *image)
253 {
254    Image_Entry *im;
255
256    if (!image) return EVAS_COLORSPACE_ARGB8888;
257    im = image;
258    return im->space;
259 }
260
261 static void
262 eng_image_mask_create(void *data __UNUSED__, void *image)
263 {
264    RGBA_Image *im;
265    int sz;
266    uint8_t *dst,*end;
267    uint32_t *src;
268
269    if (!image) return;
270    im = image;
271    if (im->mask.mask && !im->mask.dirty) return;
272
273    if (im->mask.mask) free(im->mask.mask);
274    sz = im->cache_entry.w * im->cache_entry.h;
275    im->mask.mask = malloc(sz);
276    dst = im->mask.mask;
277    if (!im->image.data)
278       evas_cache_image_load_data(&im->cache_entry);
279    src = im->image.data;
280    if (!src) return;
281    for (end = dst + sz ; dst < end ; dst ++, src ++)
282       *dst = *src >> 24;
283    im->mask.dirty = 0;
284 }
285
286
287 static void *
288 eng_image_alpha_set(void *data __UNUSED__, void *image, int has_alpha)
289 {
290    RGBA_Image *im;
291
292    if (!image) return NULL;
293    im = image;
294    if (im->cache_entry.space != EVAS_COLORSPACE_ARGB8888)
295      {
296         im->cache_entry.flags.alpha = 0;
297         return im;
298      }
299    im = (RGBA_Image *) evas_cache_image_alone(&im->cache_entry);
300    evas_common_image_colorspace_dirty(im);
301
302    im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
303    return im;
304 }
305
306 static void *
307 eng_image_border_set(void *data __UNUSED__, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
308 {
309    RGBA_Image *im;
310
311    im = image;
312    return im;
313 }
314
315 static void
316 eng_image_border_get(void *data __UNUSED__, void *image, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
317 {
318    RGBA_Image *im;
319
320    im = image;
321 }
322
323 static char *
324 eng_image_comment_get(void *data __UNUSED__, void *image, char *key __UNUSED__)
325 {
326    RGBA_Image *im;
327
328    if (!image) return NULL;
329    im = image;
330    return im->info.comment;
331 }
332
333 static char *
334 eng_image_format_get(void *data __UNUSED__, void *image __UNUSED__)
335 {
336    return NULL;
337 }
338
339 static void
340 eng_image_colorspace_set(void *data __UNUSED__, void *image, int cspace)
341 {
342    Image_Entry *im;
343
344    if (!image) return;
345    im = image;
346    evas_cache_image_colorspace(im, cspace);
347 }
348
349 static void *
350 eng_image_native_set(void *data __UNUSED__, void *image, void *native __UNUSED__)
351 {
352    return image;
353 }
354
355 static void *
356 eng_image_native_get(void *data __UNUSED__, void *image __UNUSED__)
357 {
358    return NULL;
359 }
360
361 static void *
362 eng_image_load(void *data __UNUSED__, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
363 {
364    *error = EVAS_LOAD_ERROR_NONE;
365    return evas_common_load_image_from_file(file, key, lo, error);
366 }
367
368 static void *
369 eng_image_new_from_data(void *data __UNUSED__, int w, int h, DATA32 *image_data, int alpha, int cspace)
370 {
371    return evas_cache_image_data(evas_common_image_cache_get(), w, h, image_data, alpha, cspace);
372 }
373
374 static void *
375 eng_image_new_from_copied_data(void *data __UNUSED__, int w, int h, DATA32 *image_data, int alpha, int cspace)
376 {
377    return evas_cache_image_copied_data(evas_common_image_cache_get(), w, h, image_data, alpha, cspace);
378 }
379
380 static void
381 eng_image_free(void *data __UNUSED__, void *image)
382 {
383    evas_cache_image_drop(image);
384 }
385
386 static void
387 eng_image_size_get(void *data __UNUSED__, void *image, int *w, int *h)
388 {
389    Image_Entry *im;
390
391    im = image;
392    if (w) *w = im->w;
393    if (h) *h = im->h;
394 }
395
396 static void *
397 eng_image_size_set(void *data __UNUSED__, void *image, int w, int h)
398 {
399    Image_Entry *im;
400
401    im = image;
402    return evas_cache_image_size_set(image, w, h);
403 }
404
405 static void *
406 eng_image_dirty_region(void *data __UNUSED__, void *image, int x, int y, int w, int h)
407 {
408    Image_Entry *im = image;
409
410    if (!image) return NULL;
411    return evas_cache_image_dirty(im, x, y, w, h);
412 }
413
414 static void *
415 eng_image_data_get(void *data __UNUSED__, void *image, int to_write, DATA32 **image_data, int *err)
416 {
417    RGBA_Image *im;
418    int error;
419
420    if (!image)
421      {
422         *image_data = NULL;
423         return NULL;
424      }
425    im = image;
426    error = evas_cache_image_load_data(&im->cache_entry);
427    switch (im->cache_entry.space)
428      {
429       case EVAS_COLORSPACE_ARGB8888:
430         if (to_write)
431           im = (RGBA_Image *)evas_cache_image_alone(&im->cache_entry);
432         *image_data = im->image.data;
433         break;
434       case EVAS_COLORSPACE_YCBCR422P601_PL:
435       case EVAS_COLORSPACE_YCBCR422P709_PL:
436         *image_data = im->cs.data;
437         break;
438       default:
439         abort();
440         break;
441      }
442    if (err) *err = error;
443    return im;
444 }
445
446 static void *
447 eng_image_data_put(void *data, void *image, DATA32 *image_data)
448 {
449    RGBA_Image *im, *im2;
450
451    if (!image) return NULL;
452    im = image;
453    switch (im->cache_entry.space)
454      {
455       case EVAS_COLORSPACE_ARGB8888:
456         if (image_data != im->image.data)
457           {
458              int w, h;
459
460              w = im->cache_entry.w;
461              h = im->cache_entry.h;
462              im2 = eng_image_new_from_data(data, w, h, image_data,
463                                            eng_image_alpha_get(data, image),
464                                            eng_image_colorspace_get(data, image));
465              evas_cache_image_drop(&im->cache_entry);
466              im = im2;
467           }
468         break;
469       case EVAS_COLORSPACE_YCBCR422P601_PL:
470       case EVAS_COLORSPACE_YCBCR422P709_PL:
471         if (image_data != im->cs.data)
472           {
473              if (im->cs.data)
474                {
475                   if (!im->cs.no_free) free(im->cs.data);
476                }
477              im->cs.data = image_data;
478              evas_common_image_colorspace_dirty(im);
479           }
480         break;
481       default:
482         abort();
483         break;
484      }
485    return im;
486 }
487
488 static void
489 eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
490 {
491    RGBA_Image *im = image;
492
493    if (!im) return ;
494    evas_cache_image_preload_data(&im->cache_entry, target);
495 }
496
497 static void
498 eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
499 {
500    RGBA_Image *im = image;
501
502    if (!im) return ;
503    evas_cache_image_preload_cancel(&im->cache_entry, target);
504 }
505
506 static void
507 eng_image_draw(void *data __UNUSED__, 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)
508 {
509    RGBA_Image *im;
510
511    if (!image) return;
512    im = image;
513 #ifdef BUILD_PIPE_RENDER
514    if ((cpunum > 1)
515 #ifdef EVAS_FRAME_QUEUING
516         && evas_common_frameq_enabled()
517 #endif
518         )
519      {
520         evas_common_rgba_image_scalecache_prepare((Image_Entry *)(im), 
521                                                   surface, context, smooth,
522                                                   src_x, src_y, src_w, src_h,
523                                                   dst_x, dst_y, dst_w, dst_h);
524         
525         evas_common_pipe_image_draw(im, surface, context, smooth,
526                                     src_x, src_y, src_w, src_h,
527                                     dst_x, dst_y, dst_w, dst_h);
528      }
529    else
530 #endif
531      {
532 //        if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
533 //          evas_cache_image_load_data(&im->cache_entry);
534 //        evas_common_image_colorspace_normalize(im);
535         evas_common_rgba_image_scalecache_prepare(&im->cache_entry, surface, context, smooth,
536                                                   src_x, src_y, src_w, src_h,
537                                                   dst_x, dst_y, dst_w, dst_h);
538         evas_common_rgba_image_scalecache_do(&im->cache_entry, surface, context, smooth,
539                                              src_x, src_y, src_w, src_h,
540                                              dst_x, dst_y, dst_w, dst_h);
541 /*        
542         if (smooth)
543           evas_common_scale_rgba_in_to_out_clip_smooth(im, surface, context,
544                                                        src_x, src_y, src_w, src_h,
545                                                        dst_x, dst_y, dst_w, dst_h);
546         else
547           evas_common_scale_rgba_in_to_out_clip_sample(im, surface, context,
548                                                        src_x, src_y, src_w, src_h,
549                                                        dst_x, dst_y, dst_w, dst_h);
550  */
551         evas_common_cpu_end_opt();
552      }
553 }
554
555 static void
556 eng_image_map_draw(void *data __UNUSED__, void *context, void *surface, void *image, int npoints, RGBA_Map_Point *p, int smooth, int level)
557 {
558    RGBA_Image *im;
559
560    if (!image) return;
561    if (npoints < 3) return;
562    im = image;
563
564    if ((p[0].x == p[3].x) &&
565        (p[1].x == p[2].x) &&
566        (p[0].y == p[1].y) &&
567        (p[3].y == p[2].y) &&
568        (p[0].x <= p[1].x) &&
569        (p[0].y <= p[2].y) &&
570        (p[0].u == 0) &&
571        (p[0].v == 0) &&
572        (p[1].u == (int)(im->cache_entry.w << FP)) &&
573        (p[1].v == 0) &&
574        (p[2].u == (int)(im->cache_entry.w << FP)) &&
575        (p[2].v == (int)(im->cache_entry.h << FP)) &&
576        (p[3].u == 0) &&
577        (p[3].v == (int)(im->cache_entry.h << FP)) &&
578        (p[0].col == 0xffffffff) &&
579        (p[1].col == 0xffffffff) &&
580        (p[2].col == 0xffffffff) &&
581        (p[3].col == 0xffffffff))
582      {
583         int dx, dy, dw, dh;
584
585         dx = p[0].x >> FP;
586         dy = p[0].y >> FP;
587         dw = (p[2].x >> FP) - dx;
588         dh = (p[2].y >> FP) - dy;
589         eng_image_draw
590           (data, context, surface, image,
591            0, 0, im->cache_entry.w, im->cache_entry.h,
592            dx, dy, dw, dh, smooth);
593      }
594    else
595      {
596 #ifdef BUILD_PIPE_RENDER
597         if ((cpunum > 1)
598 # ifdef EVAS_FRAME_QUEUING
599        && evas_common_frameq_enabled()
600 # endif
601         )
602           evas_common_pipe_map_draw(im, surface, context, npoints, p, smooth, level);
603         else
604 #endif
605           evas_common_map_rgba(im, surface, context, npoints, p, smooth, level);
606      }
607    evas_common_cpu_end_opt();
608
609    if (npoints > 4)
610      {
611         eng_image_map_draw(data, context, surface, image, npoints - 2, p + 2,
612                            smooth, level);
613      }
614 }
615
616 static void *
617 eng_image_map_surface_new(void *data __UNUSED__, int w, int h, int alpha)
618 {
619    void *surface;
620    DATA32 *pixels;
621    surface = evas_cache_image_copied_data(evas_common_image_cache_get(), 
622                                           w, h, NULL, alpha, 
623                                           EVAS_COLORSPACE_ARGB8888);
624    pixels = evas_cache_image_pixels(surface);
625    return surface;
626 }
627
628 static void
629 eng_image_map_surface_free(void *data __UNUSED__, void *surface)
630 {
631    evas_cache_image_drop(surface);
632 }
633
634 static void
635 eng_image_scale_hint_set(void *data __UNUSED__, void *image, int hint)
636 {
637    Image_Entry *im;
638
639    if (!image) return;
640    im = image;
641    im->scale_hint = hint;
642 }
643
644 static int
645 eng_image_scale_hint_get(void *data __UNUSED__, void *image)
646 {
647    Image_Entry *im;
648
649    if (!image) return EVAS_IMAGE_SCALE_HINT_NONE;
650    im = image;
651    return im->scale_hint;
652 }
653
654 static Eina_Bool
655 eng_image_animated_get(void *data __UNUSED__, void *image)
656 {
657    Image_Entry *im;
658
659    if (!image) return EINA_FALSE;
660    im = image;
661    return im->flags.animated;
662 }
663
664 static int
665 eng_image_animated_frame_count_get(void *data __UNUSED__, void *image)
666 {
667    Image_Entry *im;
668
669    if (!image) return -1;
670    im = image;
671    if (!im->flags.animated) return -1;
672    return im->frame_count;
673 }
674
675 static Evas_Image_Animated_Loop_Hint
676 eng_image_animated_loop_type_get(void *data __UNUSED__, void *image)
677 {
678    Image_Entry *im;
679
680    if (!image) return EVAS_IMAGE_ANIMATED_HINT_NONE;
681    im = image;
682    if (!im->flags.animated) return EVAS_IMAGE_ANIMATED_HINT_NONE;
683    return im->loop_hint;
684 }
685
686 static int
687 eng_image_animated_loop_count_get(void *data __UNUSED__, void *image)
688 {
689    Image_Entry *im;
690
691    if (!image) return -1;
692    im = image;
693    if (!im->flags.animated) return -1;
694    return im->loop_count;
695 }
696
697 static double
698 eng_image_animated_frame_duration_get(void *data __UNUSED__, void *image, int start_frame, int frame_num)
699 {
700    Image_Entry *im;
701
702    if (!image) return -1;
703    im = image;
704    if (!im->flags.animated) return -1;
705    return evas_common_load_rgba_image_frame_duration_from_file(im, start_frame, frame_num);
706 }
707
708 static Eina_Bool
709 eng_image_animated_frame_set(void *data __UNUSED__, void *image, int frame_index)
710 {
711    Image_Entry *im;
712
713    if (!image) return EINA_FALSE;
714    im = image;
715    if (!im->flags.animated) return EINA_FALSE;
716    if (im->cur_frame == frame_index) return EINA_FALSE;
717    im->cur_frame = frame_index;
718    return EINA_TRUE;
719 }
720
721 static void
722 eng_image_cache_flush(void *data __UNUSED__)
723 {
724    int tmp_size;
725
726    tmp_size = evas_common_image_get_cache();
727    evas_common_image_set_cache(0);
728    evas_common_rgba_image_scalecache_flush();
729    evas_common_image_set_cache(tmp_size);
730 }
731
732 static void
733 eng_image_cache_set(void *data __UNUSED__, int bytes)
734 {
735    evas_common_image_set_cache(bytes);
736    evas_common_rgba_image_scalecache_size_set(bytes);
737 }
738
739 static int
740 eng_image_cache_get(void *data __UNUSED__)
741 {
742    return evas_common_image_get_cache();
743 }
744
745 static Evas_Font_Set *
746 eng_font_load(void *data __UNUSED__, const char *name, int size,
747       Font_Rend_Flags wanted_rend)
748 {
749    return (Evas_Font_Set *) evas_common_font_load(name, size, wanted_rend);
750 }
751
752 static Evas_Font_Set *
753 eng_font_memory_load(void *data __UNUSED__, char *name, int size, const void *fdata, int fdata_size, Font_Rend_Flags wanted_rend)
754 {
755    return (Evas_Font_Set *) evas_common_font_memory_load(name, size, fdata,
756          fdata_size, wanted_rend);
757 }
758
759 static Evas_Font_Set *
760 eng_font_add(void *data __UNUSED__, Evas_Font_Set *font, const char *name, int size, Font_Rend_Flags wanted_rend)
761 {
762    return (Evas_Font_Set *) evas_common_font_add((RGBA_Font *) font, name,
763          size, wanted_rend);
764 }
765
766 static Evas_Font_Set *
767 eng_font_memory_add(void *data __UNUSED__, Evas_Font_Set *font, char *name, int size, const void *fdata, int fdata_size, Font_Rend_Flags wanted_rend)
768 {
769    return (Evas_Font_Set *) evas_common_font_memory_add((RGBA_Font *) font,
770          name, size, fdata, fdata_size, wanted_rend);
771 }
772
773 static void
774 eng_font_free(void *data __UNUSED__, Evas_Font_Set *font)
775 {
776    evas_common_font_free((RGBA_Font *) font);
777 }
778
779 static int
780 eng_font_ascent_get(void *data __UNUSED__, Evas_Font_Set *font)
781 {
782    return evas_common_font_ascent_get((RGBA_Font *) font);
783 }
784
785 static int
786 eng_font_descent_get(void *data __UNUSED__, Evas_Font_Set *font)
787 {
788    return evas_common_font_descent_get((RGBA_Font *) font);
789 }
790
791 static int
792 eng_font_max_ascent_get(void *data __UNUSED__, Evas_Font_Set *font)
793 {
794    return evas_common_font_max_ascent_get((RGBA_Font *) font);
795 }
796
797 static int
798 eng_font_max_descent_get(void *data __UNUSED__, Evas_Font_Set *font)
799 {
800    return evas_common_font_max_descent_get((RGBA_Font *) font);
801 }
802
803 static void
804 eng_font_string_size_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props, int *w, int *h)
805 {
806    evas_common_font_query_size((RGBA_Font *) font, text_props, w, h);
807 }
808
809 static int
810 eng_font_inset_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props)
811 {
812    return evas_common_font_query_inset((RGBA_Font *) font, text_props);
813 }
814
815 static int
816 eng_font_right_inset_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props)
817 {
818    return evas_common_font_query_right_inset((RGBA_Font *) font, text_props);
819 }
820
821 static int
822 eng_font_h_advance_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props)
823 {
824    int h, v;
825
826    evas_common_font_query_advance((RGBA_Font *) font, text_props, &h, &v);
827    return h;
828 }
829
830 static int
831 eng_font_v_advance_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props)
832 {
833    int h, v;
834
835    evas_common_font_query_advance((RGBA_Font *) font, text_props, &h, &v);
836    return v;
837 }
838
839 static int
840 eng_font_pen_coords_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props, int pos, int *cpen_x, int *cy, int *cadv, int *ch)
841 {
842    return evas_common_font_query_pen_coords((RGBA_Font *) font, text_props, pos, cpen_x, cy, cadv, ch);
843 }
844
845 static Eina_Bool
846 eng_font_text_props_info_create(void *data __UNUSED__, Evas_Font_Instance *fi, const Eina_Unicode *text, Evas_Text_Props *text_props, const Evas_BiDi_Paragraph_Props *par_props, size_t par_pos, size_t len)
847 {
848    return evas_common_text_props_content_create((RGBA_Font_Int *) fi, text,
849          text_props, par_props, par_pos, len);
850 }
851
852 static int
853 eng_font_char_coords_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props, int pos, int *cx, int *cy, int *cw, int *ch)
854 {
855    return evas_common_font_query_char_coords((RGBA_Font *) font, text_props, pos, cx, cy, cw, ch);
856 }
857
858 static int
859 eng_font_char_at_coords_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props, int x, int y, int *cx, int *cy, int *cw, int *ch)
860 {
861    return evas_common_font_query_char_at_coords((RGBA_Font *) font, text_props, x, y, cx, cy, cw, ch);
862 }
863
864 static int
865 eng_font_last_up_to_pos(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props, int x, int y)
866 {
867    return evas_common_font_query_last_up_to_pos((RGBA_Font *) font, text_props, x, y);
868 }
869
870 static int
871 eng_font_run_font_end_get(void *data __UNUSED__, Evas_Font_Set *font, Evas_Font_Instance **script_fi, Evas_Font_Instance **cur_fi, Evas_Script_Type script, const Eina_Unicode *text, int run_len)
872 {
873    return evas_common_font_query_run_font_end_get((RGBA_Font *) font,
874          (RGBA_Font_Int **) script_fi, (RGBA_Font_Int **) cur_fi,
875          script, text, run_len);
876 }
877
878 static void
879 eng_font_draw(void *data __UNUSED__, void *context, void *surface, Evas_Font_Set *font, int x, int y, int w __UNUSED__, int h __UNUSED__, int ow __UNUSED__, int oh __UNUSED__, const Evas_Text_Props *text_props)
880 {
881 #ifdef BUILD_PIPE_RENDER
882    if ((cpunum > 1)
883 #ifdef EVAS_FRAME_QUEUING
884         && evas_common_frameq_enabled()
885 #endif
886         )
887      evas_common_pipe_text_draw(surface, context, (RGBA_Font *) font, x, y,
888            text_props);
889    else
890 #endif   
891      {
892         evas_common_font_draw(surface, context, (RGBA_Font *) font, x, y,
893               text_props);
894         evas_common_cpu_end_opt();
895      }
896 }
897
898 static void
899 eng_font_cache_flush(void *data __UNUSED__)
900 {
901    int tmp_size;
902
903    tmp_size = evas_common_font_cache_get();
904    evas_common_font_cache_set(0);
905    evas_common_font_flush();
906    evas_common_font_cache_set(tmp_size);
907 }
908
909 static void
910 eng_font_cache_set(void *data __UNUSED__, int bytes)
911 {
912    evas_common_font_cache_set(bytes);
913 }
914
915 static int
916 eng_font_cache_get(void *data __UNUSED__)
917 {
918    return evas_common_font_cache_get();
919 }
920
921 static void
922 eng_font_hinting_set(void *data __UNUSED__, Evas_Font_Set *font, int hinting)
923 {
924    evas_common_font_hinting_set((RGBA_Font *) font, hinting);
925 }
926
927 static int
928 eng_font_hinting_can_hint(void *data __UNUSED__, int hinting)
929 {
930    return evas_common_hinting_available(hinting);
931 }
932
933 static Eina_Bool
934 eng_canvas_alpha_get(void *data __UNUSED__, void *info __UNUSED__)
935 {
936    return EINA_TRUE;
937 }
938
939
940 /* Filter API */
941 #if 0 // filtering disabled
942 static void
943 eng_image_draw_filtered(void *data __UNUSED__, void *context __UNUSED__,
944                         void *surface, void *image, Evas_Filter_Info *filter)
945 {
946    Evas_Software_Filter_Fn fn;
947    RGBA_Image *im = image;
948
949    fn = evas_filter_software_get(filter);
950    if (!fn) return;
951    if (im->cache_entry.cache) evas_cache_image_load_data(&im->cache_entry);
952    fn(filter, image, surface);
953    return;
954 }
955
956 static Filtered_Image *
957 eng_image_filtered_get(void *image, uint8_t *key, size_t keylen)
958 {
959    RGBA_Image *im = image;
960    Filtered_Image *fi;
961    Eina_List *l;
962
963    for (l = im->filtered ; l ; l = l->next)
964      {
965          fi = l->data;
966          if (fi->keylen != keylen) continue;
967          if (memcmp(key, fi->key, keylen) != 0) continue;
968          fi->ref ++;
969          return fi;
970      }
971
972    return NULL;
973 }
974
975 static Filtered_Image *
976 eng_image_filtered_save(void *image, void *fimage, uint8_t *key, size_t keylen)
977 {
978    RGBA_Image *im = image;
979    Filtered_Image *fi;
980    Eina_List *l;
981
982    for (l = im->filtered ; l ; l = l->next)
983      {
984         fi = l->data;
985         if (fi->keylen != keylen) continue;
986         if (memcmp(key, fi->key, keylen) == 0) continue;
987         evas_cache_image_drop((void *)fi->image);
988         fi->image = fimage;
989         return fi;
990      }
991
992    fi = calloc(1,sizeof(Filtered_Image));
993    if (!fi) return NULL;
994
995    fi->keylen = keylen;
996    fi->key = malloc(keylen);
997    memcpy(fi->key, key, keylen);
998    fi->image = fimage;
999    fi->ref = 1;
1000
1001    im->filtered = eina_list_prepend(im->filtered, fi);
1002
1003    return fi;
1004 }
1005
1006 static void
1007 eng_image_filtered_free(void *image, Filtered_Image *fi)
1008 {
1009    RGBA_Image *im = image;
1010
1011    fi->ref --;
1012    if (fi->ref) return;
1013
1014    free(fi->key);
1015    evas_cache_image_drop(&fi->image->cache_entry);
1016    fi->image = NULL;
1017
1018    im->filtered = eina_list_remove(im->filtered, fi);
1019 }
1020 #endif
1021
1022 static int
1023 eng_image_load_error_get(void *data __UNUSED__, void *image)
1024 {
1025    RGBA_Image *im;
1026    
1027    if (!image) return EVAS_LOAD_ERROR_NONE;
1028    im = image;
1029    return im->cache_entry.load_error;
1030 }
1031
1032 /*
1033  *****
1034  **
1035  ** ENGINE API
1036  **
1037  *****
1038  */
1039
1040 static Evas_Func func =
1041 {
1042    NULL,
1043      NULL,
1044      NULL,
1045      NULL,
1046      NULL,
1047      NULL,
1048      NULL,
1049      NULL,
1050      NULL,
1051      NULL,
1052      NULL,
1053      NULL,
1054      NULL,
1055      eng_output_dump,
1056      /* draw context virtual methods */
1057      eng_context_new,
1058      eng_canvas_alpha_get,
1059      eng_context_free,
1060      eng_context_clip_set,
1061      eng_context_clip_clip,
1062      eng_context_clip_unset,
1063      eng_context_clip_get,
1064      eng_context_mask_set,
1065      eng_context_mask_unset,
1066      eng_context_color_set,
1067      eng_context_color_get,
1068      eng_context_multiplier_set,
1069      eng_context_multiplier_unset,
1070      eng_context_multiplier_get,
1071      eng_context_cutout_add,
1072      eng_context_cutout_clear,
1073      eng_context_anti_alias_set,
1074      eng_context_anti_alias_get,
1075      eng_context_color_interpolation_set,
1076      eng_context_color_interpolation_get,
1077      eng_context_render_op_set,
1078      eng_context_render_op_get,
1079      /* rect draw funcs */
1080      eng_rectangle_draw,
1081      /* line draw funcs */
1082      eng_line_draw,
1083      /* polygon draw funcs */
1084      eng_polygon_point_add,
1085      eng_polygon_points_clear,
1086      eng_polygon_draw,
1087      /* image draw funcs */
1088      eng_image_load,
1089      eng_image_new_from_data,
1090      eng_image_new_from_copied_data,
1091      eng_image_free,
1092      eng_image_size_get,
1093      eng_image_size_set,
1094      NULL,
1095      eng_image_dirty_region,
1096      eng_image_data_get,
1097      eng_image_data_put,
1098      eng_image_data_preload_request,
1099      eng_image_data_preload_cancel,
1100      eng_image_alpha_set,
1101      eng_image_alpha_get,
1102      eng_image_border_set,
1103      eng_image_border_get,
1104      eng_image_draw,
1105      eng_image_comment_get,
1106      eng_image_format_get,
1107      eng_image_colorspace_set,
1108      eng_image_colorspace_get,
1109      eng_image_mask_create,
1110      eng_image_native_set,
1111      eng_image_native_get,
1112      /* image cache funcs */
1113      eng_image_cache_flush,
1114      eng_image_cache_set,
1115      eng_image_cache_get,
1116      /* font draw functions */
1117      eng_font_load,
1118      eng_font_memory_load,
1119      eng_font_add,
1120      eng_font_memory_add,
1121      eng_font_free,
1122      eng_font_ascent_get,
1123      eng_font_descent_get,
1124      eng_font_max_ascent_get,
1125      eng_font_max_descent_get,
1126      eng_font_string_size_get,
1127      eng_font_inset_get,
1128      eng_font_h_advance_get,
1129      eng_font_v_advance_get,
1130      eng_font_char_coords_get,
1131      eng_font_char_at_coords_get,
1132      eng_font_draw,
1133      /* font cache functions */
1134      eng_font_cache_flush,
1135      eng_font_cache_set,
1136      eng_font_cache_get,
1137      /* font hinting functions */
1138      eng_font_hinting_set,
1139      eng_font_hinting_can_hint,
1140      eng_image_scale_hint_set,
1141      eng_image_scale_hint_get,
1142      /* more font draw functions */
1143      eng_font_last_up_to_pos,
1144      eng_image_map_draw,
1145      eng_image_map_surface_new,
1146      eng_image_map_surface_free,
1147      NULL, // eng_image_content_hint_set - software doesn't use it
1148      NULL, // eng_image_content_hint_get - software doesn't use it
1149      eng_font_pen_coords_get,
1150      eng_font_text_props_info_create,
1151      eng_font_right_inset_get,
1152 #if 0 // filtering disabled
1153      eng_image_draw_filtered,
1154      eng_image_filtered_get,
1155      eng_image_filtered_save,
1156      eng_image_filtered_free,
1157 #endif   
1158      NULL, // FIXME: need software mesa for gl rendering <- gl_surface_create
1159      NULL, // FIXME: need software mesa for gl rendering <- gl_surface_destroy
1160      NULL, // FIXME: need software mesa for gl rendering <- gl_context_create
1161      NULL, // FIXME: need software mesa for gl rendering <- gl_context_destroy
1162      NULL, // FIXME: need software mesa for gl rendering <- gl_make_current
1163      NULL, // FIXME: need software mesa for gl rendering <- gl_proc_address_get
1164      NULL, // FIXME: need software mesa for gl rendering <- gl_native_surface_get
1165      NULL, // FIXME: need software mesa for gl rendering <- gl_api_get
1166      eng_image_load_error_get,
1167      eng_font_run_font_end_get,
1168      eng_image_animated_get,
1169      eng_image_animated_frame_count_get,
1170      eng_image_animated_loop_type_get,
1171      eng_image_animated_loop_count_get,
1172      eng_image_animated_frame_duration_get,
1173      eng_image_animated_frame_set
1174    /* FUTURE software generic calls go here */
1175 };
1176
1177 /*
1178  *****
1179  **
1180  ** MODULE ACCESSIBLE API API
1181  **
1182  *****
1183  */
1184
1185 static int
1186 module_open(Evas_Module *em)
1187 {
1188    if (!em) return 0;
1189    _evas_soft_gen_log_dom = eina_log_domain_register
1190      ("evas-software_generic", EVAS_DEFAULT_LOG_COLOR);
1191    if(_evas_soft_gen_log_dom<0)
1192      {
1193         EINA_LOG_ERR("Can not create a module log domain.");
1194         return 0;
1195      }
1196    em->functions = (void *)(&func);
1197    cpunum = eina_cpu_count();
1198    return 1;
1199 }
1200
1201 static void
1202 module_close(Evas_Module *em __UNUSED__)
1203 {
1204   eina_log_domain_unregister(_evas_soft_gen_log_dom);
1205 }
1206
1207 static Evas_Module_Api evas_modapi =
1208 {
1209    EVAS_MODULE_API_VERSION,
1210    "software_generic",
1211    "none",
1212    {
1213      module_open,
1214      module_close
1215    }
1216 };
1217
1218 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, software_generic);
1219
1220 #ifndef EVAS_STATIC_BUILD_SOFTWARE_GENERIC
1221 EVAS_EINA_MODULE_DEFINE(engine, software_generic);
1222 #endif