merged evas image masking code from brett
[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 static void
118 eng_context_cutout_add(void *data __UNUSED__, void *context, int x, int y, int w, int h)
119 {
120    evas_common_draw_context_add_cutout(context, x, y, w, h);
121 }
122
123 static void
124 eng_context_cutout_clear(void *data __UNUSED__, void *context)
125 {
126    evas_common_draw_context_clear_cutouts(context);
127 }
128
129 static void
130 eng_context_anti_alias_set(void *data __UNUSED__, void *context, unsigned char aa)
131 {
132    evas_common_draw_context_set_anti_alias(context, aa);
133 }
134
135 static unsigned char
136 eng_context_anti_alias_get(void *data __UNUSED__, void *context)
137 {
138    return ((RGBA_Draw_Context *)context)->anti_alias;
139 }
140
141 static void
142 eng_context_color_interpolation_set(void *data __UNUSED__, void *context, int color_space)
143 {
144    evas_common_draw_context_set_color_interpolation(context, color_space);
145 }
146
147 static int
148 eng_context_color_interpolation_get(void *data __UNUSED__, void *context)
149 {
150    return ((RGBA_Draw_Context *)context)->interpolation.color_space;
151 }
152
153 static void
154 eng_context_render_op_set(void *data __UNUSED__, void *context, int op)
155 {
156    evas_common_draw_context_set_render_op(context, op);
157 }
158
159 static int
160 eng_context_render_op_get(void *data __UNUSED__, void *context)
161 {
162    return ((RGBA_Draw_Context *)context)->render_op;
163 }
164
165
166
167 static void
168 eng_rectangle_draw(void *data __UNUSED__, void *context, void *surface, int x, int y, int w, int h)
169 {
170 #ifdef BUILD_PIPE_RENDER
171    if ((cpunum > 1)
172 #ifdef EVAS_FRAME_QUEUING
173         && evas_common_frameq_enabled()
174 #endif
175         )
176      evas_common_pipe_rectangle_draw(surface, context, x, y, w, h);
177    else
178 #endif
179      {
180         evas_common_rectangle_draw(surface, context, x, y, w, h);
181         evas_common_cpu_end_opt();
182      }
183 }
184
185 static void
186 eng_line_draw(void *data __UNUSED__, void *context, void *surface, int x1, int y1, int x2, int y2)
187 {
188 #ifdef BUILD_PIPE_RENDER
189    if ((cpunum > 1)
190  #ifdef EVAS_FRAME_QUEUING
191         && evas_common_frameq_enabled()
192 #endif
193         )
194     evas_common_pipe_line_draw(surface, context, x1, y1, x2, y2);
195    else
196 #endif   
197      {
198         evas_common_line_draw(surface, context, x1, y1, x2, y2);
199         evas_common_cpu_end_opt();
200      }
201 }
202
203 static void *
204 eng_polygon_point_add(void *data __UNUSED__, void *context __UNUSED__, void *polygon, int x, int y)
205 {
206    return evas_common_polygon_point_add(polygon, x, y);
207 }
208
209 static void *
210 eng_polygon_points_clear(void *data __UNUSED__, void *context __UNUSED__, void *polygon)
211 {
212    return evas_common_polygon_points_clear(polygon);
213 }
214
215 static void
216 eng_polygon_draw(void *data __UNUSED__, void *context, void *surface, void *polygon, int x, int y)
217 {
218 #ifdef BUILD_PIPE_RENDER
219    if ((cpunum > 1)
220 #ifdef EVAS_FRAME_QUEUING
221         && evas_common_frameq_enabled()
222 #endif
223         )
224      evas_common_pipe_poly_draw(surface, context, polygon, x, y);
225    else
226 #endif
227      {
228         evas_common_polygon_draw(surface, context, polygon, x, y);
229         evas_common_cpu_end_opt();
230      }
231 }
232
233 static int
234 eng_image_alpha_get(void *data __UNUSED__, void *image)
235 {
236    Image_Entry *im;
237
238    if (!image) return 1;
239    im = image;
240    switch (im->space)
241      {
242       case EVAS_COLORSPACE_ARGB8888:
243         if (im->flags.alpha) return 1;
244       default:
245         break;
246      }
247    return 0;
248 }
249
250 static int
251 eng_image_colorspace_get(void *data __UNUSED__, void *image)
252 {
253    Image_Entry *im;
254
255    if (!image) return EVAS_COLORSPACE_ARGB8888;
256    im = image;
257    return im->space;
258 }
259
260 static void
261 eng_image_mask_create(void *data __UNUSED__, void *image)
262 {
263    RGBA_Image *im;
264    int sz;
265    uint8_t *dst,*end;
266    uint32_t *src;
267
268    if (!image) return;
269    im = image;
270    if (im->mask.mask && !im->mask.dirty) return;
271
272    if (im->mask.mask) free(im->mask.mask);
273    sz = im->cache_entry.w * im->cache_entry.h;
274    im->mask.mask = malloc(sz);
275    dst = im->mask.mask;
276    if (!im->image.data)
277       evas_cache_image_load_data(&im->cache_entry);
278    src = im->image.data;
279    for (end = dst + sz ; dst < end ; dst ++, src ++)
280       *dst = *src >> 24;
281    im->mask.dirty = 0;
282 }
283
284
285 static void *
286 eng_image_alpha_set(void *data __UNUSED__, void *image, int has_alpha)
287 {
288    RGBA_Image *im;
289
290    if (!image) return NULL;
291    im = image;
292    if (im->cache_entry.space != EVAS_COLORSPACE_ARGB8888)
293      {
294         im->cache_entry.flags.alpha = 0;
295         return im;
296      }
297    im = (RGBA_Image *) evas_cache_image_alone(&im->cache_entry);
298    evas_common_image_colorspace_dirty(im);
299
300    im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
301    return im;
302 }
303
304 static void *
305 eng_image_border_set(void *data __UNUSED__, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
306 {
307    RGBA_Image *im;
308
309    im = image;
310    return im;
311 }
312
313 static void
314 eng_image_border_get(void *data __UNUSED__, void *image, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
315 {
316    RGBA_Image *im;
317
318    im = image;
319 }
320
321 static char *
322 eng_image_comment_get(void *data __UNUSED__, void *image, char *key __UNUSED__)
323 {
324    RGBA_Image *im;
325
326    if (!image) return NULL;
327    im = image;
328    return im->info.comment;
329 }
330
331 static char *
332 eng_image_format_get(void *data __UNUSED__, void *image __UNUSED__)
333 {
334    return NULL;
335 }
336
337 static void
338 eng_image_colorspace_set(void *data __UNUSED__, void *image, int cspace)
339 {
340    Image_Entry *im;
341
342    if (!image) return;
343    im = image;
344    evas_cache_image_colorspace(im, cspace);
345 }
346
347 static void *
348 eng_image_native_set(void *data __UNUSED__, void *image, void *native __UNUSED__)
349 {
350    return image;
351 }
352
353 static void *
354 eng_image_native_get(void *data __UNUSED__, void *image __UNUSED__)
355 {
356    return NULL;
357 }
358
359 static void *
360 eng_image_load(void *data __UNUSED__, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
361 {
362    *error = EVAS_LOAD_ERROR_NONE;
363    return evas_common_load_image_from_file(file, key, lo, error);
364 }
365
366 static void *
367 eng_image_new_from_data(void *data __UNUSED__, int w, int h, DATA32 *image_data, int alpha, int cspace)
368 {
369    return evas_cache_image_data(evas_common_image_cache_get(), w, h, image_data, alpha, cspace);
370 }
371
372 static void *
373 eng_image_new_from_copied_data(void *data __UNUSED__, int w, int h, DATA32 *image_data, int alpha, int cspace)
374 {
375    return evas_cache_image_copied_data(evas_common_image_cache_get(), w, h, image_data, alpha, cspace);
376 }
377
378 static void
379 eng_image_free(void *data __UNUSED__, void *image)
380 {
381    evas_cache_image_drop(image);
382 }
383
384 static void
385 eng_image_size_get(void *data __UNUSED__, void *image, int *w, int *h)
386 {
387    Image_Entry *im;
388
389    im = image;
390    if (w) *w = im->w;
391    if (h) *h = im->h;
392 }
393
394 static void *
395 eng_image_size_set(void *data __UNUSED__, void *image, int w, int h)
396 {
397    Image_Entry *im;
398
399    im = image;
400    return evas_cache_image_size_set(image, w, h);
401 }
402
403 static void *
404 eng_image_dirty_region(void *data __UNUSED__, void *image, int x, int y, int w, int h)
405 {
406    Image_Entry *im = image;
407
408    if (!image) return NULL;
409    return evas_cache_image_dirty(im, x, y, w, h);
410 }
411
412 static void *
413 eng_image_data_get(void *data __UNUSED__, void *image, int to_write, DATA32 **image_data)
414 {
415    RGBA_Image *im;
416
417    if (!image)
418      {
419         *image_data = NULL;
420         return NULL;
421      }
422    im = image;
423    evas_cache_image_load_data(&im->cache_entry);
424    switch (im->cache_entry.space)
425      {
426       case EVAS_COLORSPACE_ARGB8888:
427         if (to_write)
428           im = (RGBA_Image *) evas_cache_image_alone(&im->cache_entry);
429         *image_data = im->image.data;
430         break;
431       case EVAS_COLORSPACE_YCBCR422P601_PL:
432       case EVAS_COLORSPACE_YCBCR422P709_PL:
433         *image_data = im->cs.data;
434         break;
435       default:
436         abort();
437         break;
438      }
439    return im;
440 }
441
442 static void *
443 eng_image_data_put(void *data, void *image, DATA32 *image_data)
444 {
445    RGBA_Image *im, *im2;
446
447    if (!image) return NULL;
448    im = image;
449    switch (im->cache_entry.space)
450      {
451       case EVAS_COLORSPACE_ARGB8888:
452         if (image_data != im->image.data)
453           {
454              int w, h;
455
456              w = im->cache_entry.w;
457              h = im->cache_entry.h;
458              im2 = eng_image_new_from_data(data, w, h, image_data,
459                                            eng_image_alpha_get(data, image),
460                                            eng_image_colorspace_get(data, image));
461              evas_cache_image_drop(&im->cache_entry);
462              im = im2;
463           }
464         break;
465       case EVAS_COLORSPACE_YCBCR422P601_PL:
466       case EVAS_COLORSPACE_YCBCR422P709_PL:
467         if (image_data != im->cs.data)
468           {
469              if (im->cs.data)
470                {
471                   if (!im->cs.no_free) free(im->cs.data);
472                }
473              im->cs.data = image_data;
474           }
475         break;
476       default:
477         abort();
478         break;
479      }
480    return im;
481 }
482
483 static void
484 eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
485 {
486    RGBA_Image *im = image;
487
488    if (!im) return ;
489    evas_cache_image_preload_data(&im->cache_entry, target);
490 }
491
492 static void
493 eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
494 {
495    RGBA_Image *im = image;
496
497    if (!im) return ;
498    evas_cache_image_preload_cancel(&im->cache_entry, target);
499 }
500
501 static void
502 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)
503 {
504    RGBA_Image *im;
505
506    if (!image) return;
507    im = image;
508 #ifdef BUILD_PIPE_RENDER
509    if ((cpunum > 1)
510 #ifdef EVAS_FRAME_QUEUING
511         && evas_common_frameq_enabled()
512 #endif
513         )
514      {
515         evas_common_rgba_image_scalecache_prepare((Image_Entry *)(im),
516                                                   surface, context, smooth,
517                                                   src_x, src_y, src_w, src_h,
518                                                   dst_x, dst_y, dst_w, dst_h);
519
520         evas_common_pipe_image_draw(im, surface, context, smooth,
521                                     src_x, src_y, src_w, src_h,
522                                     dst_x, dst_y, dst_w, dst_h);
523      }
524    else
525 #endif
526      {
527 //        if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
528 //          evas_cache_image_load_data(&im->cache_entry);
529 //        evas_common_image_colorspace_normalize(im);
530         evas_common_rgba_image_scalecache_prepare(&im->cache_entry, surface, context, smooth,
531                                                   src_x, src_y, src_w, src_h,
532                                                   dst_x, dst_y, dst_w, dst_h);
533         evas_common_rgba_image_scalecache_do(&im->cache_entry, surface, context, smooth,
534                                              src_x, src_y, src_w, src_h,
535                                              dst_x, dst_y, dst_w, dst_h);
536 /*
537         if (smooth)
538           evas_common_scale_rgba_in_to_out_clip_smooth(im, surface, context,
539                                                        src_x, src_y, src_w, src_h,
540                                                        dst_x, dst_y, dst_w, dst_h);
541         else
542           evas_common_scale_rgba_in_to_out_clip_sample(im, surface, context,
543                                                        src_x, src_y, src_w, src_h,
544                                                        dst_x, dst_y, dst_w, dst_h);
545  */
546         evas_common_cpu_end_opt();
547      }
548 }
549
550 static void
551 eng_image_map_draw(void *data __UNUSED__, void *context, void *surface, void *image, int npoints, RGBA_Map_Point *p, int smooth, int level)
552 {
553    RGBA_Image *im;
554
555    if (!image) return;
556    if (npoints < 3) return;
557    im = image;
558
559    if ((p[0].x == p[3].x) &&
560        (p[1].x == p[2].x) &&
561        (p[0].y == p[1].y) &&
562        (p[3].y == p[2].y) &&
563        (p[0].x <= p[1].x) &&
564        (p[0].y <= p[2].y) &&
565        (p[0].u == 0) &&
566        (p[0].v == 0) &&
567        (p[1].u == (int)(im->cache_entry.w << FP)) &&
568        (p[1].v == 0) &&
569        (p[2].u == (int)(im->cache_entry.w << FP)) &&
570        (p[2].v == (int)(im->cache_entry.h << FP)) &&
571        (p[3].u == 0) &&
572        (p[3].v == (int)(im->cache_entry.h << FP)) &&
573        (p[0].col == 0xffffffff) &&
574        (p[1].col == 0xffffffff) &&
575        (p[2].col == 0xffffffff) &&
576        (p[3].col == 0xffffffff))
577      {
578         int dx, dy, dw, dh;
579
580         dx = p[0].x >> FP;
581         dy = p[0].y >> FP;
582         dw = (p[2].x >> FP) - dx;
583         dh = (p[2].y >> FP) - dy;
584         eng_image_draw
585           (data, context, surface, image,
586            0, 0, im->cache_entry.w, im->cache_entry.h,
587            dx, dy, dw, dh, smooth);
588      }
589    else
590      {
591 #ifdef BUILD_PIPE_RENDER
592         if ((cpunum > 1)
593 # ifdef EVAS_FRAME_QUEUING
594        && evas_common_frameq_enabled()
595 # endif
596         )
597           evas_common_pipe_map_draw(im, surface, context, npoints, p, smooth, level);
598         else
599 #endif
600           evas_common_map_rgba(im, surface, context, npoints, p, smooth, level);
601      }
602    evas_common_cpu_end_opt();
603
604    if (npoints > 4)
605      {
606         eng_image_map_draw(data, context, surface, image, npoints - 2, p + 2,
607                         smooth, level);
608      }
609 }
610
611 static void *
612 eng_image_map_surface_new(void *data __UNUSED__, int w, int h, int alpha)
613 {
614    void *surface;
615    DATA32 *pixels;
616    surface = evas_cache_image_copied_data(evas_common_image_cache_get(), 
617                                           w, h, NULL, alpha, 
618                                           EVAS_COLORSPACE_ARGB8888);
619    pixels = evas_cache_image_pixels(surface);
620    return surface;
621 }
622
623 static void
624 eng_image_map_surface_free(void *data __UNUSED__, void *surface)
625 {
626    evas_cache_image_drop(surface);
627 }
628
629 static void
630 eng_image_scale_hint_set(void *data __UNUSED__, void *image, int hint)
631 {
632    Image_Entry *im;
633
634    if (!image) return;
635    im = image;
636    im->scale_hint = hint;
637 }
638
639 static int
640 eng_image_scale_hint_get(void *data __UNUSED__, void *image)
641 {
642    Image_Entry *im;
643
644    if (!image) return EVAS_IMAGE_SCALE_HINT_NONE;
645    im = image;
646    return im->scale_hint;
647 }
648
649 static void
650 eng_image_cache_flush(void *data __UNUSED__)
651 {
652    int tmp_size;
653
654    tmp_size = evas_common_image_get_cache();
655    evas_common_image_set_cache(0);
656    evas_common_rgba_image_scalecache_flush();
657    evas_common_image_set_cache(tmp_size);
658 }
659
660 static void
661 eng_image_cache_set(void *data __UNUSED__, int bytes)
662 {
663    evas_common_image_set_cache(bytes);
664    evas_common_rgba_image_scalecache_size_set(bytes);
665 }
666
667 static int
668 eng_image_cache_get(void *data __UNUSED__)
669 {
670    return evas_common_image_get_cache();
671 }
672
673 static void *
674 eng_font_load(void *data __UNUSED__, const char *name, int size)
675 {
676    return evas_common_font_load(name, size);
677 }
678
679 static void *
680 eng_font_memory_load(void *data __UNUSED__, char *name, int size, const void *fdata, int fdata_size)
681 {
682    return evas_common_font_memory_load(name, size, fdata, fdata_size);
683 }
684
685 static void *
686 eng_font_add(void *data __UNUSED__, void *font, const char *name, int size)
687 {
688    return evas_common_font_add(font, name, size);
689 }
690
691 static void *
692 eng_font_memory_add(void *data __UNUSED__, void *font, char *name, int size, const void *fdata, int fdata_size)
693 {
694    return evas_common_font_memory_add(font, name, size, fdata, fdata_size);
695 }
696
697 static void
698 eng_font_free(void *data __UNUSED__, void *font)
699 {
700    evas_common_font_free(font);
701 }
702
703 static int
704 eng_font_ascent_get(void *data __UNUSED__, void *font)
705 {
706    return evas_common_font_ascent_get(font);
707 }
708
709 static int
710 eng_font_descent_get(void *data __UNUSED__, void *font)
711 {
712    return evas_common_font_descent_get(font);
713 }
714
715 static int
716 eng_font_max_ascent_get(void *data __UNUSED__, void *font)
717 {
718    return evas_common_font_max_ascent_get(font);
719 }
720
721 static int
722 eng_font_max_descent_get(void *data __UNUSED__, void *font)
723 {
724    return evas_common_font_max_descent_get(font);
725 }
726
727 static void
728 eng_font_string_size_get(void *data __UNUSED__, void *font, const Eina_Unicode *text, const Evas_BiDi_Props *intl_props, int *w, int *h)
729 {
730    evas_common_font_query_size(font, text, intl_props, w, h);
731 }
732
733 static int
734 eng_font_inset_get(void *data __UNUSED__, void *font, const Eina_Unicode *text)
735 {
736    return evas_common_font_query_inset(font, text);
737 }
738
739 static int
740 eng_font_h_advance_get(void *data __UNUSED__, void *font, const Eina_Unicode *text, const Evas_BiDi_Props *intl_props)
741 {
742    int h, v;
743
744    evas_common_font_query_advance(font, text, intl_props, &h, &v);
745    return h;
746 }
747
748 static int
749 eng_font_v_advance_get(void *data __UNUSED__, void *font, const Eina_Unicode *text, const Evas_BiDi_Props *intl_props)
750 {
751    int h, v;
752
753    evas_common_font_query_advance(font, text, intl_props, &h, &v);
754    return v;
755 }
756
757 static int
758 eng_font_char_coords_get(void *data __UNUSED__, void *font, const Eina_Unicode *text, const Evas_BiDi_Props *intl_props, int pos, int *cx, int *cy, int *cw, int *ch)
759 {
760    return evas_common_font_query_char_coords(font, text, intl_props, pos, cx, cy, cw, ch);
761 }
762
763 static int
764 eng_font_char_at_coords_get(void *data __UNUSED__, void *font, const Eina_Unicode *text, const Evas_BiDi_Props *intl_props, int x, int y, int *cx, int *cy, int *cw, int *ch)
765 {
766    return evas_common_font_query_char_at_coords(font, text, intl_props, x, y, cx, cy, cw, ch);
767 }
768
769 static int
770 eng_font_last_up_to_pos(void *data __UNUSED__, void *font, const Eina_Unicode *text, const Evas_BiDi_Props *intl_props, int x, int y)
771 {
772    return evas_common_font_query_last_up_to_pos(font, text, intl_props, x, y);
773 }
774
775 static void
776 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_BiDi_Props *intl_props)
777 {
778 #ifdef BUILD_PIPE_RENDER
779    if ((cpunum > 1)
780 #ifdef EVAS_FRAME_QUEUING
781         && evas_common_frameq_enabled()
782 #endif
783         )
784      evas_common_pipe_text_draw(surface, context, font, x, y, text, intl_props);
785    else
786 #endif   
787      {
788         evas_common_font_draw(surface, context, font, x, y, text, intl_props);
789         evas_common_cpu_end_opt();
790      }
791 }
792
793 static void
794 eng_font_cache_flush(void *data __UNUSED__)
795 {
796    evas_common_font_flush();
797 }
798
799 static void
800 eng_font_cache_set(void *data __UNUSED__, int bytes)
801 {
802    evas_common_font_cache_set(bytes);
803 }
804
805 static int
806 eng_font_cache_get(void *data __UNUSED__)
807 {
808    return evas_common_font_cache_get();
809 }
810
811 static void
812 eng_font_hinting_set(void *data __UNUSED__, void *font, int hinting)
813 {
814    evas_common_font_hinting_set(font, hinting);
815 }
816
817 static int
818 eng_font_hinting_can_hint(void *data __UNUSED__, int hinting)
819 {
820    return evas_common_hinting_available(hinting);
821 }
822
823 static Eina_Bool
824 eng_canvas_alpha_get(void *data __UNUSED__, void *info __UNUSED__)
825 {
826    return EINA_TRUE;
827 }
828
829 /*
830  *****
831  **
832  ** ENGINE API
833  **
834  *****
835  */
836
837 static Evas_Func func =
838 {
839    NULL,
840      NULL,
841      NULL,
842      NULL,
843      NULL,
844      NULL,
845      NULL,
846      NULL,
847      NULL,
848      NULL,
849      NULL,
850      NULL,
851      NULL,
852      eng_output_dump,
853      /* draw context virtual methods */
854      eng_context_new,
855      eng_canvas_alpha_get,
856      eng_context_free,
857      eng_context_clip_set,
858      eng_context_clip_clip,
859      eng_context_clip_unset,
860      eng_context_clip_get,
861      eng_context_mask_set,
862      eng_context_mask_unset,
863      eng_context_color_set,
864      eng_context_color_get,
865      eng_context_multiplier_set,
866      eng_context_multiplier_unset,
867      eng_context_multiplier_get,
868      eng_context_cutout_add,
869      eng_context_cutout_clear,
870      eng_context_anti_alias_set,
871      eng_context_anti_alias_get,
872      eng_context_color_interpolation_set,
873      eng_context_color_interpolation_get,
874      eng_context_render_op_set,
875      eng_context_render_op_get,
876      /* rect draw funcs */
877      eng_rectangle_draw,
878      /* line draw funcs */
879      eng_line_draw,
880      /* polygon draw funcs */
881      eng_polygon_point_add,
882      eng_polygon_points_clear,
883      eng_polygon_draw,
884      /* image draw funcs */
885      eng_image_load,
886      eng_image_new_from_data,
887      eng_image_new_from_copied_data,
888      eng_image_free,
889      eng_image_size_get,
890      eng_image_size_set,
891      NULL,
892      eng_image_dirty_region,
893      eng_image_data_get,
894      eng_image_data_put,
895      eng_image_data_preload_request,
896      eng_image_data_preload_cancel,
897      eng_image_alpha_set,
898      eng_image_alpha_get,
899      eng_image_border_set,
900      eng_image_border_get,
901      eng_image_draw,
902      eng_image_comment_get,
903      eng_image_format_get,
904      eng_image_colorspace_set,
905      eng_image_colorspace_get,
906      eng_image_mask_create,
907      eng_image_native_set,
908      eng_image_native_get,
909      /* image cache funcs */
910      eng_image_cache_flush,
911      eng_image_cache_set,
912      eng_image_cache_get,
913      /* font draw functions */
914      eng_font_load,
915      eng_font_memory_load,
916      eng_font_add,
917      eng_font_memory_add,
918      eng_font_free,
919      eng_font_ascent_get,
920      eng_font_descent_get,
921      eng_font_max_ascent_get,
922      eng_font_max_descent_get,
923      eng_font_string_size_get,
924      eng_font_inset_get,
925      eng_font_h_advance_get,
926      eng_font_v_advance_get,
927      eng_font_char_coords_get,
928      eng_font_char_at_coords_get,
929      eng_font_draw,
930      /* font cache functions */
931      eng_font_cache_flush,
932      eng_font_cache_set,
933      eng_font_cache_get,
934      /* font hinting functions */
935      eng_font_hinting_set,
936      eng_font_hinting_can_hint,
937      eng_image_scale_hint_set,
938      eng_image_scale_hint_get,
939      /* more font draw functions */
940      eng_font_last_up_to_pos,
941      /* FUTURE software generic calls go here (done) */
942      eng_image_map_draw,
943      eng_image_map_surface_new,
944      eng_image_map_surface_free,
945      NULL, // eng_image_content_hint_set - software doesn't use it
946      NULL // eng_image_content_hint_get - software doesn't use it
947      /* FUTURE software generic calls go here */
948 };
949
950 /*
951  *****
952  **
953  ** MODULE ACCESSIBLE API API
954  **
955  *****
956  */
957
958 static int
959 module_open(Evas_Module *em)
960 {
961    if (!em) return 0;
962    _evas_soft_gen_log_dom = eina_log_domain_register
963      ("evas-software_generic", EVAS_DEFAULT_LOG_COLOR);
964    if(_evas_soft_gen_log_dom<0)
965      {
966         EINA_LOG_ERR("Can not create a module log domain.");
967         return 0;
968      }
969    em->functions = (void *)(&func);
970    cpunum = eina_cpu_count();
971    return 1;
972 }
973
974 static void
975 module_close(Evas_Module *em __UNUSED__)
976 {
977   eina_log_domain_unregister(_evas_soft_gen_log_dom);
978 }
979
980 static Evas_Module_Api evas_modapi =
981 {
982    EVAS_MODULE_API_VERSION,
983    "software_generic",
984    "none",
985    {
986      module_open,
987      module_close
988    }
989 };
990
991 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, software_generic);
992
993 #ifndef EVAS_STATIC_BUILD_SOFTWARE_GENERIC
994 EVAS_EINA_MODULE_DEFINE(engine, software_generic);
995 #endif