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