Evas: Software_Generic: Fix typo? for __UNUSED__.
[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 Eina_Bool
262 eng_image_can_region_get(void *data __UNUSED__, void *image)
263 {
264    Image_Entry *im;
265    if (!image) return EINA_FALSE;
266    im = image;
267    return ((Evas_Image_Load_Func*) im->info.loader)->do_region;
268 }
269
270 static void
271 eng_image_mask_create(void *data __UNUSED__, void *image)
272 {
273    RGBA_Image *im;
274    int sz;
275    uint8_t *dst,*end;
276    uint32_t *src;
277
278    if (!image) return;
279    im = image;
280    if (im->mask.mask && !im->mask.dirty) return;
281
282    if (im->mask.mask) free(im->mask.mask);
283    sz = im->cache_entry.w * im->cache_entry.h;
284    im->mask.mask = malloc(sz);
285    dst = im->mask.mask;
286    if (!im->image.data)
287       evas_cache_image_load_data(&im->cache_entry);
288    src = (void*) im->image.data;
289    if (!src) return;
290    for (end = dst + sz ; dst < end ; dst ++, src ++)
291       *dst = *src >> 24;
292    im->mask.dirty = 0;
293 }
294
295
296 static void *
297 eng_image_alpha_set(void *data __UNUSED__, void *image, int has_alpha)
298 {
299    RGBA_Image *im;
300
301    if (!image) return NULL;
302    im = image;
303    if (im->cache_entry.space != EVAS_COLORSPACE_ARGB8888)
304      {
305         im->cache_entry.flags.alpha = 0;
306         return im;
307      }
308    im = (RGBA_Image *) evas_cache_image_alone(&im->cache_entry);
309    evas_common_image_colorspace_dirty(im);
310
311    im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
312    return im;
313 }
314
315 static void *
316 eng_image_border_set(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    return im;
322 }
323
324 static void
325 eng_image_border_get(void *data __UNUSED__, void *image, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
326 {
327    RGBA_Image *im;
328
329    im = image;
330 }
331
332 static char *
333 eng_image_comment_get(void *data __UNUSED__, void *image, char *key __UNUSED__)
334 {
335    RGBA_Image *im;
336
337    if (!image) return NULL;
338    im = image;
339    return im->info.comment;
340 }
341
342 static char *
343 eng_image_format_get(void *data __UNUSED__, void *image __UNUSED__)
344 {
345    return NULL;
346 }
347
348 static void
349 eng_image_colorspace_set(void *data __UNUSED__, void *image, int cspace)
350 {
351    Image_Entry *im;
352
353    if (!image) return;
354    im = image;
355    evas_cache_image_colorspace(im, cspace);
356 }
357
358 static void *
359 eng_image_native_set(void *data __UNUSED__, void *image, void *native __UNUSED__)
360 {
361    return image;
362 }
363
364 static void *
365 eng_image_native_get(void *data __UNUSED__, void *image __UNUSED__)
366 {
367    return NULL;
368 }
369
370 static void *
371 eng_image_load(void *data __UNUSED__, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
372 {
373    *error = EVAS_LOAD_ERROR_NONE;
374    return evas_common_load_image_from_file(file, key, lo, error);
375 }
376
377 static void *
378 eng_image_new_from_data(void *data __UNUSED__, int w, int h, DATA32 *image_data, int alpha, int cspace)
379 {
380    return evas_cache_image_data(evas_common_image_cache_get(), w, h, image_data, alpha, cspace);
381 }
382
383 static void *
384 eng_image_new_from_copied_data(void *data __UNUSED__, int w, int h, DATA32 *image_data, int alpha, int cspace)
385 {
386    return evas_cache_image_copied_data(evas_common_image_cache_get(), w, h, image_data, alpha, cspace);
387 }
388
389 static void
390 eng_image_free(void *data __UNUSED__, void *image)
391 {
392    evas_cache_image_drop(image);
393 }
394
395 static void
396 eng_image_size_get(void *data __UNUSED__, void *image, int *w, int *h)
397 {
398    Image_Entry *im;
399
400    im = image;
401    if (w) *w = im->w;
402    if (h) *h = im->h;
403 }
404
405 static void *
406 eng_image_size_set(void *data __UNUSED__, void *image, int w, int h)
407 {
408    Image_Entry *im;
409
410    im = image;
411    return evas_cache_image_size_set(image, w, h);
412 }
413
414 static void *
415 eng_image_dirty_region(void *data __UNUSED__, void *image, int x, int y, int w, int h)
416 {
417    Image_Entry *im = image;
418
419    if (!image) return NULL;
420    return evas_cache_image_dirty(im, x, y, w, h);
421 }
422
423 static void *
424 eng_image_data_get(void *data __UNUSED__, void *image, int to_write, DATA32 **image_data, int *err)
425 {
426    RGBA_Image *im;
427    int error;
428
429    if (!image)
430      {
431         *image_data = NULL;
432         return NULL;
433      }
434    im = image;
435    error = evas_cache_image_load_data(&im->cache_entry);
436    switch (im->cache_entry.space)
437      {
438       case EVAS_COLORSPACE_ARGB8888:
439         if (to_write)
440           im = (RGBA_Image *)evas_cache_image_alone(&im->cache_entry);
441         *image_data = im->image.data;
442         break;
443       case EVAS_COLORSPACE_YCBCR422P601_PL:
444       case EVAS_COLORSPACE_YCBCR422P709_PL:
445       case EVAS_COLORSPACE_YCBCR422601_PL:
446       case EVAS_COLORSPACE_YCBCR420NV12601_PL:
447       case EVAS_COLORSPACE_YCBCR420TM12601_PL:
448         *image_data = im->cs.data;
449         break;
450       default:
451         abort();
452         break;
453      }
454    if (err) *err = error;
455    return im;
456 }
457
458 static void *
459 eng_image_data_put(void *data, void *image, DATA32 *image_data)
460 {
461    RGBA_Image *im, *im2;
462
463    if (!image) return NULL;
464    im = image;
465    switch (im->cache_entry.space)
466      {
467       case EVAS_COLORSPACE_ARGB8888:
468         if (image_data != im->image.data)
469           {
470              int w, h;
471
472              w = im->cache_entry.w;
473              h = im->cache_entry.h;
474              im2 = eng_image_new_from_data(data, w, h, image_data,
475                                            eng_image_alpha_get(data, image),
476                                            eng_image_colorspace_get(data, image));
477              evas_cache_image_drop(&im->cache_entry);
478              im = im2;
479           }
480         break;
481       case EVAS_COLORSPACE_YCBCR422P601_PL:
482       case EVAS_COLORSPACE_YCBCR422P709_PL:
483       case EVAS_COLORSPACE_YCBCR422601_PL:
484       case EVAS_COLORSPACE_YCBCR420NV12601_PL:
485       case EVAS_COLORSPACE_YCBCR420TM12601_PL:
486         if (image_data != im->cs.data)
487           {
488              if (im->cs.data)
489                {
490                   if (!im->cs.no_free) free(im->cs.data);
491                }
492              im->cs.data = image_data;
493           }
494         evas_common_image_colorspace_dirty(im);
495         break;
496       default:
497         abort();
498         break;
499      }
500    return im;
501 }
502
503 static void
504 eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
505 {
506    RGBA_Image *im = image;
507
508    if (!im) return ;
509    evas_cache_image_preload_data(&im->cache_entry, target);
510 }
511
512 static void
513 eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
514 {
515    RGBA_Image *im = image;
516
517    if (!im) return ;
518    evas_cache_image_preload_cancel(&im->cache_entry, target);
519 }
520
521 static void
522 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)
523 {
524    RGBA_Image *im;
525
526    if (!image) return;
527    im = image;
528 #ifdef BUILD_PIPE_RENDER
529    if ((cpunum > 1)
530 #ifdef EVAS_FRAME_QUEUING
531         && evas_common_frameq_enabled()
532 #endif
533         )
534      {
535         evas_common_rgba_image_scalecache_prepare((Image_Entry *)(im), 
536                                                   surface, context, smooth,
537                                                   src_x, src_y, src_w, src_h,
538                                                   dst_x, dst_y, dst_w, dst_h);
539         
540         evas_common_pipe_image_draw(im, surface, context, smooth,
541                                     src_x, src_y, src_w, src_h,
542                                     dst_x, dst_y, dst_w, dst_h);
543      }
544    else
545 #endif
546      {
547 //        if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
548 //          evas_cache_image_load_data(&im->cache_entry);
549 //        evas_common_image_colorspace_normalize(im);
550         evas_common_rgba_image_scalecache_prepare(&im->cache_entry, surface, context, smooth,
551                                                   src_x, src_y, src_w, src_h,
552                                                   dst_x, dst_y, dst_w, dst_h);
553         evas_common_rgba_image_scalecache_do(&im->cache_entry, surface, context, smooth,
554                                              src_x, src_y, src_w, src_h,
555                                              dst_x, dst_y, dst_w, dst_h);
556 /*        
557         if (smooth)
558           evas_common_scale_rgba_in_to_out_clip_smooth(im, surface, context,
559                                                        src_x, src_y, src_w, src_h,
560                                                        dst_x, dst_y, dst_w, dst_h);
561         else
562           evas_common_scale_rgba_in_to_out_clip_sample(im, surface, context,
563                                                        src_x, src_y, src_w, src_h,
564                                                        dst_x, dst_y, dst_w, dst_h);
565  */
566         evas_common_cpu_end_opt();
567      }
568 }
569
570 static void
571 eng_image_map_draw(void *data __UNUSED__, void *context, void *surface, void *image, int npoints, RGBA_Map_Point *p, int smooth, int level)
572 {
573    RGBA_Image *im;
574
575    if (!image) return;
576    if (npoints < 3) return;
577    im = image;
578
579    if ((p[0].x == p[3].x) &&
580        (p[1].x == p[2].x) &&
581        (p[0].y == p[1].y) &&
582        (p[3].y == p[2].y) &&
583        (p[0].x <= p[1].x) &&
584        (p[0].y <= p[2].y) &&
585        (p[0].u == 0) &&
586        (p[0].v == 0) &&
587        (p[1].u == (int)(im->cache_entry.w << FP)) &&
588        (p[1].v == 0) &&
589        (p[2].u == (int)(im->cache_entry.w << FP)) &&
590        (p[2].v == (int)(im->cache_entry.h << FP)) &&
591        (p[3].u == 0) &&
592        (p[3].v == (int)(im->cache_entry.h << FP)) &&
593        (p[0].col == 0xffffffff) &&
594        (p[1].col == 0xffffffff) &&
595        (p[2].col == 0xffffffff) &&
596        (p[3].col == 0xffffffff))
597      {
598         int dx, dy, dw, dh;
599
600         dx = p[0].x >> FP;
601         dy = p[0].y >> FP;
602         dw = (p[2].x >> FP) - dx;
603         dh = (p[2].y >> FP) - dy;
604         eng_image_draw
605           (data, context, surface, image,
606            0, 0, im->cache_entry.w, im->cache_entry.h,
607            dx, dy, dw, dh, smooth);
608      }
609    else
610      {
611 #ifdef BUILD_PIPE_RENDER
612         if ((cpunum > 1)
613 # ifdef EVAS_FRAME_QUEUING
614        && evas_common_frameq_enabled()
615 # endif
616         )
617           evas_common_pipe_map_draw(im, surface, context, npoints, p, smooth, level);
618         else
619 #endif
620           evas_common_map_rgba(im, surface, context, npoints, p, smooth, level);
621      }
622    evas_common_cpu_end_opt();
623
624    if (npoints > 4)
625      {
626         eng_image_map_draw(data, context, surface, image, npoints - 2, p + 2,
627                            smooth, level);
628      }
629 }
630
631 static void *
632 eng_image_map_surface_new(void *data __UNUSED__, int w, int h, int alpha)
633 {
634    void *surface;
635    DATA32 *pixels;
636    surface = evas_cache_image_copied_data(evas_common_image_cache_get(), 
637                                           w, h, NULL, alpha, 
638                                           EVAS_COLORSPACE_ARGB8888);
639    pixels = evas_cache_image_pixels(surface);
640    return surface;
641 }
642
643 static void
644 eng_image_map_surface_free(void *data __UNUSED__, void *surface)
645 {
646    evas_cache_image_drop(surface);
647 }
648
649 static void
650 eng_image_scale_hint_set(void *data __UNUSED__, void *image, int hint)
651 {
652    Image_Entry *im;
653
654    if (!image) return;
655    im = image;
656    im->scale_hint = hint;
657 }
658
659 static int
660 eng_image_scale_hint_get(void *data __UNUSED__, void *image)
661 {
662    Image_Entry *im;
663
664    if (!image) return EVAS_IMAGE_SCALE_HINT_NONE;
665    im = image;
666    return im->scale_hint;
667 }
668
669 static Eina_Bool
670 eng_image_animated_get(void *data __UNUSED__, void *image)
671 {
672    Image_Entry *im;
673
674    if (!image) return EINA_FALSE;
675    im = image;
676    return im->flags.animated;
677 }
678
679 static int
680 eng_image_animated_frame_count_get(void *data __UNUSED__, void *image)
681 {
682    Image_Entry *im;
683
684    if (!image) return -1;
685    im = image;
686    if (!im->flags.animated) return -1;
687    return im->frame_count;
688 }
689
690 static Evas_Image_Animated_Loop_Hint
691 eng_image_animated_loop_type_get(void *data __UNUSED__, void *image)
692 {
693    Image_Entry *im;
694
695    if (!image) return EVAS_IMAGE_ANIMATED_HINT_NONE;
696    im = image;
697    if (!im->flags.animated) return EVAS_IMAGE_ANIMATED_HINT_NONE;
698    return im->loop_hint;
699 }
700
701 static int
702 eng_image_animated_loop_count_get(void *data __UNUSED__, void *image)
703 {
704    Image_Entry *im;
705
706    if (!image) return -1;
707    im = image;
708    if (!im->flags.animated) return -1;
709    return im->loop_count;
710 }
711
712 static double
713 eng_image_animated_frame_duration_get(void *data __UNUSED__, void *image, int start_frame, int frame_num)
714 {
715    Image_Entry *im;
716
717    if (!image) return -1;
718    im = image;
719    if (!im->flags.animated) return -1;
720    return evas_common_load_rgba_image_frame_duration_from_file(im, start_frame, frame_num);
721 }
722
723 static Eina_Bool
724 eng_image_animated_frame_set(void *data __UNUSED__, void *image, int frame_index)
725 {
726    Image_Entry *im;
727
728    if (!image) return EINA_FALSE;
729    im = image;
730    if (!im->flags.animated) return EINA_FALSE;
731    if (im->cur_frame == frame_index) return EINA_FALSE;
732    im->cur_frame = frame_index;
733    return EINA_TRUE;
734 }
735
736 static void
737 eng_image_cache_flush(void *data __UNUSED__)
738 {
739    int tmp_size;
740
741    tmp_size = evas_common_image_get_cache();
742    evas_common_image_set_cache(0);
743    evas_common_rgba_image_scalecache_flush();
744    evas_common_image_set_cache(tmp_size);
745 }
746
747 static void
748 eng_image_cache_set(void *data __UNUSED__, int bytes)
749 {
750    evas_common_image_set_cache(bytes);
751    evas_common_rgba_image_scalecache_size_set(bytes);
752 }
753
754 static int
755 eng_image_cache_get(void *data __UNUSED__)
756 {
757    return evas_common_image_get_cache();
758 }
759
760 static Evas_Font_Set *
761 eng_font_load(void *data __UNUSED__, const char *name, int size,
762       Font_Rend_Flags wanted_rend)
763 {
764    return (Evas_Font_Set *) evas_common_font_load(name, size, wanted_rend);
765 }
766
767 static Evas_Font_Set *
768 eng_font_memory_load(void *data __UNUSED__, char *name, int size, const void *fdata, int fdata_size, Font_Rend_Flags wanted_rend)
769 {
770    return (Evas_Font_Set *) evas_common_font_memory_load(name, size, fdata,
771          fdata_size, wanted_rend);
772 }
773
774 static Evas_Font_Set *
775 eng_font_add(void *data __UNUSED__, Evas_Font_Set *font, const char *name, int size, Font_Rend_Flags wanted_rend)
776 {
777    return (Evas_Font_Set *) evas_common_font_add((RGBA_Font *) font, name,
778          size, wanted_rend);
779 }
780
781 static Evas_Font_Set *
782 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)
783 {
784    return (Evas_Font_Set *) evas_common_font_memory_add((RGBA_Font *) font,
785          name, size, fdata, fdata_size, wanted_rend);
786 }
787
788 static void
789 eng_font_free(void *data __UNUSED__, Evas_Font_Set *font)
790 {
791    evas_common_font_free((RGBA_Font *) font);
792 }
793
794 static int
795 eng_font_ascent_get(void *data __UNUSED__, Evas_Font_Set *font)
796 {
797    return evas_common_font_ascent_get((RGBA_Font *) font);
798 }
799
800 static int
801 eng_font_descent_get(void *data __UNUSED__, Evas_Font_Set *font)
802 {
803    return evas_common_font_descent_get((RGBA_Font *) font);
804 }
805
806 static int
807 eng_font_max_ascent_get(void *data __UNUSED__, Evas_Font_Set *font)
808 {
809    return evas_common_font_max_ascent_get((RGBA_Font *) font);
810 }
811
812 static int
813 eng_font_max_descent_get(void *data __UNUSED__, Evas_Font_Set *font)
814 {
815    return evas_common_font_max_descent_get((RGBA_Font *) font);
816 }
817
818 static void
819 eng_font_string_size_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props, int *w, int *h)
820 {
821    evas_common_font_query_size((RGBA_Font *) font, text_props, w, h);
822 }
823
824 static int
825 eng_font_inset_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props)
826 {
827    return evas_common_font_query_inset((RGBA_Font *) font, text_props);
828 }
829
830 static int
831 eng_font_right_inset_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props)
832 {
833    return evas_common_font_query_right_inset((RGBA_Font *) font, text_props);
834 }
835
836 static int
837 eng_font_h_advance_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props)
838 {
839    int h, v;
840
841    evas_common_font_query_advance((RGBA_Font *) font, text_props, &h, &v);
842    return h;
843 }
844
845 static int
846 eng_font_v_advance_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props)
847 {
848    int h, v;
849
850    evas_common_font_query_advance((RGBA_Font *) font, text_props, &h, &v);
851    return v;
852 }
853
854 static int
855 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)
856 {
857    return evas_common_font_query_pen_coords((RGBA_Font *) font, text_props, pos, cpen_x, cy, cadv, ch);
858 }
859
860 static Eina_Bool
861 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)
862 {
863    return evas_common_text_props_content_create((RGBA_Font_Int *) fi, text,
864          text_props, par_props, par_pos, len);
865 }
866
867 static int
868 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)
869 {
870    return evas_common_font_query_char_coords((RGBA_Font *) font, text_props, pos, cx, cy, cw, ch);
871 }
872
873 static int
874 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)
875 {
876    return evas_common_font_query_char_at_coords((RGBA_Font *) font, text_props, x, y, cx, cy, cw, ch);
877 }
878
879 static int
880 eng_font_last_up_to_pos(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props, int x, int y)
881 {
882    return evas_common_font_query_last_up_to_pos((RGBA_Font *) font, text_props, x, y);
883 }
884
885 static int
886 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)
887 {
888    return evas_common_font_query_run_font_end_get((RGBA_Font *) font,
889          (RGBA_Font_Int **) script_fi, (RGBA_Font_Int **) cur_fi,
890          script, text, run_len);
891 }
892
893 static void
894 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)
895 {
896 #ifdef BUILD_PIPE_RENDER
897    if ((cpunum > 1)
898 #ifdef EVAS_FRAME_QUEUING
899         && evas_common_frameq_enabled()
900 #endif
901         )
902      evas_common_pipe_text_draw(surface, context, (RGBA_Font *) font, x, y,
903            text_props);
904    else
905 #endif   
906      {
907         evas_common_font_draw(surface, context, (RGBA_Font *) font, x, y,
908               text_props);
909         evas_common_cpu_end_opt();
910      }
911 }
912
913 static void
914 eng_font_cache_flush(void *data __UNUSED__)
915 {
916    int tmp_size;
917
918    tmp_size = evas_common_font_cache_get();
919    evas_common_font_cache_set(0);
920    evas_common_font_flush();
921    evas_common_font_cache_set(tmp_size);
922 }
923
924 static void
925 eng_font_cache_set(void *data __UNUSED__, int bytes)
926 {
927    evas_common_font_cache_set(bytes);
928 }
929
930 static int
931 eng_font_cache_get(void *data __UNUSED__)
932 {
933    return evas_common_font_cache_get();
934 }
935
936 static void
937 eng_font_hinting_set(void *data __UNUSED__, Evas_Font_Set *font, int hinting)
938 {
939    evas_common_font_hinting_set((RGBA_Font *) font, hinting);
940 }
941
942 static int
943 eng_font_hinting_can_hint(void *data __UNUSED__, int hinting)
944 {
945    return evas_common_hinting_available(hinting);
946 }
947
948 static Eina_Bool
949 eng_canvas_alpha_get(void *data __UNUSED__, void *info __UNUSED__)
950 {
951    return EINA_TRUE;
952 }
953
954
955 /* Filter API */
956 #if 0 // filtering disabled
957 static void
958 eng_image_draw_filtered(void *data __UNUSED__, void *context __UNUSED__,
959                         void *surface, void *image, Evas_Filter_Info *filter)
960 {
961    Evas_Software_Filter_Fn fn;
962    RGBA_Image *im = image;
963
964    fn = evas_filter_software_get(filter);
965    if (!fn) return;
966    if (im->cache_entry.cache) evas_cache_image_load_data(&im->cache_entry);
967    fn(filter, image, surface);
968    return;
969 }
970
971 static Filtered_Image *
972 eng_image_filtered_get(void *image, uint8_t *key, size_t keylen)
973 {
974    RGBA_Image *im = image;
975    Filtered_Image *fi;
976    Eina_List *l;
977
978    for (l = im->filtered ; l ; l = l->next)
979      {
980          fi = l->data;
981          if (fi->keylen != keylen) continue;
982          if (memcmp(key, fi->key, keylen) != 0) continue;
983          fi->ref ++;
984          return fi;
985      }
986
987    return NULL;
988 }
989
990 static Filtered_Image *
991 eng_image_filtered_save(void *image, void *fimage, uint8_t *key, size_t keylen)
992 {
993    RGBA_Image *im = image;
994    Filtered_Image *fi;
995    Eina_List *l;
996
997    for (l = im->filtered ; l ; l = l->next)
998      {
999         fi = l->data;
1000         if (fi->keylen != keylen) continue;
1001         if (memcmp(key, fi->key, keylen) == 0) continue;
1002         evas_cache_image_drop((void *)fi->image);
1003         fi->image = fimage;
1004         return fi;
1005      }
1006
1007    fi = calloc(1,sizeof(Filtered_Image));
1008    if (!fi) return NULL;
1009
1010    fi->keylen = keylen;
1011    fi->key = malloc(keylen);
1012    memcpy(fi->key, key, keylen);
1013    fi->image = fimage;
1014    fi->ref = 1;
1015
1016    im->filtered = eina_list_prepend(im->filtered, fi);
1017
1018    return fi;
1019 }
1020
1021 static void
1022 eng_image_filtered_free(void *image, Filtered_Image *fi)
1023 {
1024    RGBA_Image *im = image;
1025
1026    fi->ref --;
1027    if (fi->ref) return;
1028
1029    free(fi->key);
1030    evas_cache_image_drop(&fi->image->cache_entry);
1031    fi->image = NULL;
1032
1033    im->filtered = eina_list_remove(im->filtered, fi);
1034 }
1035 #endif
1036
1037 static int
1038 eng_image_load_error_get(void *data __UNUSED__, void *image)
1039 {
1040    RGBA_Image *im;
1041    
1042    if (!image) return EVAS_LOAD_ERROR_NONE;
1043    im = image;
1044    return im->cache_entry.load_error;
1045 }
1046
1047 /*
1048  *****
1049  **
1050  ** ENGINE API
1051  **
1052  *****
1053  */
1054
1055 static Evas_Func func =
1056 {
1057    NULL,
1058      NULL,
1059      NULL,
1060      NULL,
1061      NULL,
1062      NULL,
1063      NULL,
1064      NULL,
1065      NULL,
1066      NULL,
1067      NULL,
1068      NULL,
1069      NULL,
1070      eng_output_dump,
1071      /* draw context virtual methods */
1072      eng_context_new,
1073      eng_canvas_alpha_get,
1074      eng_context_free,
1075      eng_context_clip_set,
1076      eng_context_clip_clip,
1077      eng_context_clip_unset,
1078      eng_context_clip_get,
1079      eng_context_mask_set,
1080      eng_context_mask_unset,
1081      eng_context_color_set,
1082      eng_context_color_get,
1083      eng_context_multiplier_set,
1084      eng_context_multiplier_unset,
1085      eng_context_multiplier_get,
1086      eng_context_cutout_add,
1087      eng_context_cutout_clear,
1088      eng_context_anti_alias_set,
1089      eng_context_anti_alias_get,
1090      eng_context_color_interpolation_set,
1091      eng_context_color_interpolation_get,
1092      eng_context_render_op_set,
1093      eng_context_render_op_get,
1094      /* rect draw funcs */
1095      eng_rectangle_draw,
1096      /* line draw funcs */
1097      eng_line_draw,
1098      /* polygon draw funcs */
1099      eng_polygon_point_add,
1100      eng_polygon_points_clear,
1101      eng_polygon_draw,
1102      /* image draw funcs */
1103      eng_image_load,
1104      eng_image_new_from_data,
1105      eng_image_new_from_copied_data,
1106      eng_image_free,
1107      eng_image_size_get,
1108      eng_image_size_set,
1109      NULL,
1110      eng_image_dirty_region,
1111      eng_image_data_get,
1112      eng_image_data_put,
1113      eng_image_data_preload_request,
1114      eng_image_data_preload_cancel,
1115      eng_image_alpha_set,
1116      eng_image_alpha_get,
1117      eng_image_border_set,
1118      eng_image_border_get,
1119      eng_image_draw,
1120      eng_image_comment_get,
1121      eng_image_format_get,
1122      eng_image_colorspace_set,
1123      eng_image_colorspace_get,
1124      eng_image_can_region_get,
1125      eng_image_mask_create,
1126      eng_image_native_set,
1127      eng_image_native_get,
1128      /* image cache funcs */
1129      eng_image_cache_flush,
1130      eng_image_cache_set,
1131      eng_image_cache_get,
1132      /* font draw functions */
1133      eng_font_load,
1134      eng_font_memory_load,
1135      eng_font_add,
1136      eng_font_memory_add,
1137      eng_font_free,
1138      eng_font_ascent_get,
1139      eng_font_descent_get,
1140      eng_font_max_ascent_get,
1141      eng_font_max_descent_get,
1142      eng_font_string_size_get,
1143      eng_font_inset_get,
1144      eng_font_h_advance_get,
1145      eng_font_v_advance_get,
1146      eng_font_char_coords_get,
1147      eng_font_char_at_coords_get,
1148      eng_font_draw,
1149      /* font cache functions */
1150      eng_font_cache_flush,
1151      eng_font_cache_set,
1152      eng_font_cache_get,
1153      /* font hinting functions */
1154      eng_font_hinting_set,
1155      eng_font_hinting_can_hint,
1156      eng_image_scale_hint_set,
1157      eng_image_scale_hint_get,
1158      /* more font draw functions */
1159      eng_font_last_up_to_pos,
1160      eng_image_map_draw,
1161      eng_image_map_surface_new,
1162      eng_image_map_surface_free,
1163      NULL, // eng_image_content_hint_set - software doesn't use it
1164      NULL, // eng_image_content_hint_get - software doesn't use it
1165      eng_font_pen_coords_get,
1166      eng_font_text_props_info_create,
1167      eng_font_right_inset_get,
1168 #if 0 // filtering disabled
1169      eng_image_draw_filtered,
1170      eng_image_filtered_get,
1171      eng_image_filtered_save,
1172      eng_image_filtered_free,
1173 #endif   
1174      NULL, // FIXME: need software mesa for gl rendering <- gl_surface_create
1175      NULL, // FIXME: need software mesa for gl rendering <- gl_surface_destroy
1176      NULL, // FIXME: need software mesa for gl rendering <- gl_context_create
1177      NULL, // FIXME: need software mesa for gl rendering <- gl_context_destroy
1178      NULL, // FIXME: need software mesa for gl rendering <- gl_make_current
1179      NULL, // FIXME: need software mesa for gl rendering <- gl_string_query
1180      NULL, // FIXME: need software mesa for gl rendering <- gl_proc_address_get
1181      NULL, // FIXME: need software mesa for gl rendering <- gl_native_surface_get
1182      NULL, // FIXME: need software mesa for gl rendering <- gl_api_get
1183      eng_image_load_error_get,
1184      eng_font_run_font_end_get,
1185      eng_image_animated_get,
1186      eng_image_animated_frame_count_get,
1187      eng_image_animated_loop_type_get,
1188      eng_image_animated_loop_count_get,
1189      eng_image_animated_frame_duration_get,
1190      eng_image_animated_frame_set,
1191      NULL
1192    /* FUTURE software generic calls go here */
1193 };
1194
1195 /*
1196  *****
1197  **
1198  ** MODULE ACCESSIBLE API API
1199  **
1200  *****
1201  */
1202
1203 static int
1204 module_open(Evas_Module *em)
1205 {
1206    if (!em) return 0;
1207    _evas_soft_gen_log_dom = eina_log_domain_register
1208      ("evas-software_generic", EVAS_DEFAULT_LOG_COLOR);
1209    if(_evas_soft_gen_log_dom<0)
1210      {
1211         EINA_LOG_ERR("Can not create a module log domain.");
1212         return 0;
1213      }
1214    em->functions = (void *)(&func);
1215    cpunum = eina_cpu_count();
1216    return 1;
1217 }
1218
1219 static void
1220 module_close(Evas_Module *em __UNUSED__)
1221 {
1222   eina_log_domain_unregister(_evas_soft_gen_log_dom);
1223 }
1224
1225 static Evas_Module_Api evas_modapi =
1226 {
1227    EVAS_MODULE_API_VERSION,
1228    "software_generic",
1229    "none",
1230    {
1231      module_open,
1232      module_close
1233    }
1234 };
1235
1236 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, software_generic);
1237
1238 #ifndef EVAS_STATIC_BUILD_SOFTWARE_GENERIC
1239 EVAS_EINA_MODULE_DEFINE(engine, software_generic);
1240 #endif