svn update: 48959 (latest:48959)
[framework/uifw/evas.git] / src / modules / engines / software_generic / evas_engine.c
1 #include "evas_common.h"
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_cutout_add(void *data __UNUSED__, void *context, int x, int y, int w, int h)
101 {
102    evas_common_draw_context_add_cutout(context, x, y, w, h);
103 }
104
105 static void
106 eng_context_cutout_clear(void *data __UNUSED__, void *context)
107 {
108    evas_common_draw_context_clear_cutouts(context);
109 }
110
111 static void
112 eng_context_anti_alias_set(void *data __UNUSED__, void *context, unsigned char aa)
113 {
114    evas_common_draw_context_set_anti_alias(context, aa);
115 }
116
117 static unsigned char
118 eng_context_anti_alias_get(void *data __UNUSED__, void *context)
119 {
120    return ((RGBA_Draw_Context *)context)->anti_alias;
121 }
122
123 static void
124 eng_context_color_interpolation_set(void *data __UNUSED__, void *context, int color_space)
125 {
126    evas_common_draw_context_set_color_interpolation(context, color_space);
127 }
128
129 static int
130 eng_context_color_interpolation_get(void *data __UNUSED__, void *context)
131 {
132    return ((RGBA_Draw_Context *)context)->interpolation.color_space;
133 }
134
135 static void
136 eng_context_render_op_set(void *data __UNUSED__, void *context, int op)
137 {
138    evas_common_draw_context_set_render_op(context, op);
139 }
140
141 static int
142 eng_context_render_op_get(void *data __UNUSED__, void *context)
143 {
144    return ((RGBA_Draw_Context *)context)->render_op;
145 }
146
147
148
149 static void
150 eng_rectangle_draw(void *data __UNUSED__, void *context, void *surface, int x, int y, int w, int h)
151 {
152 #ifdef BUILD_PIPE_RENDER
153    if (cpunum > 1)
154      evas_common_pipe_rectangle_draw(surface, context, x, y, w, h);
155    else
156 #endif
157      {
158         evas_common_rectangle_draw(surface, context, x, y, w, h);
159         evas_common_cpu_end_opt();
160      }
161 }
162
163 static void
164 eng_line_draw(void *data __UNUSED__, void *context, void *surface, int x1, int y1, int x2, int y2)
165 {
166 #ifdef BUILD_PIPE_RENDER
167    if (cpunum > 1)
168      evas_common_pipe_line_draw(surface, context, x1, y1, x2, y2);
169    else
170 #endif   
171      {
172         evas_common_line_draw(surface, context, x1, y1, x2, y2);
173         evas_common_cpu_end_opt();
174      }
175 }
176
177 static void *
178 eng_polygon_point_add(void *data __UNUSED__, void *context __UNUSED__, void *polygon, int x, int y)
179 {
180    return evas_common_polygon_point_add(polygon, x, y);
181 }
182
183 static void *
184 eng_polygon_points_clear(void *data __UNUSED__, void *context __UNUSED__, void *polygon)
185 {
186    return evas_common_polygon_points_clear(polygon);
187 }
188
189 static void
190 eng_polygon_draw(void *data __UNUSED__, void *context, void *surface, void *polygon, int x, int y)
191 {
192 #ifdef BUILD_PIPE_RENDER
193    if (cpunum > 1)
194      evas_common_pipe_poly_draw(surface, context, polygon, x, y);
195    else
196 #endif
197      {
198         evas_common_polygon_draw(surface, context, polygon, x, y);
199         evas_common_cpu_end_opt();
200      }
201 }
202
203 static void
204 eng_gradient2_color_np_stop_insert(void *data __UNUSED__, void *gradient, int r, int g, int b, int a, float pos)
205 {
206    evas_common_gradient2_color_np_stop_insert(gradient, r, g, b, a, pos);
207 }
208
209 static void
210 eng_gradient2_clear(void *data __UNUSED__, void *gradient)
211 {
212    evas_common_gradient2_clear(gradient);
213 }
214
215 static void
216 eng_gradient2_fill_transform_set(void *data __UNUSED__, void *gradient, void *transform)
217 {
218    evas_common_gradient2_fill_transform_set(gradient, transform);
219 }
220
221 static void
222 eng_gradient2_fill_spread_set(void *data __UNUSED__, void *gradient, int spread)
223 {
224    evas_common_gradient2_fill_spread_set(gradient, spread);
225 }
226
227 static void *
228 eng_gradient2_linear_new(void *data __UNUSED__)
229 {
230    return evas_common_gradient2_linear_new();
231 }
232
233 static void
234 eng_gradient2_linear_free(void *data __UNUSED__, void *linear_gradient)
235 {
236    evas_common_gradient2_free(linear_gradient);
237 }
238
239 static void
240 eng_gradient2_linear_fill_set(void *data __UNUSED__, void *linear_gradient, float x0, float y0, float x1, float y1)
241 {
242    evas_common_gradient2_linear_fill_set(linear_gradient, x0, y0, x1, y1);
243 }
244
245 static int
246 eng_gradient2_linear_is_opaque(void *data __UNUSED__, void *context, void *linear_gradient, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
247 {
248    RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
249    RGBA_Gradient2 *gr = (RGBA_Gradient2 *)linear_gradient;
250
251    if (!dc || !gr || !gr->type.geometer)  return 0;
252    return !(gr->type.geometer->has_alpha(gr, dc->render_op) |
253               gr->type.geometer->has_mask(gr, dc->render_op));
254 }
255
256 static int
257 eng_gradient2_linear_is_visible(void *data __UNUSED__, void *context, void *linear_gradient, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
258 {
259    RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
260
261    if (!dc || !linear_gradient)  return 0;
262    return 1;
263 }
264
265 static void
266 eng_gradient2_linear_render_pre(void *data __UNUSED__, void *context, void *linear_gradient)
267 {
268    RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
269    RGBA_Gradient2 *gr = (RGBA_Gradient2 *)linear_gradient;
270    int  len;
271
272    if (!dc || !gr || !gr->type.geometer)  return;
273    gr->type.geometer->geom_update(gr);
274    len = gr->type.geometer->get_map_len(gr);
275    evas_common_gradient2_map(dc, gr, len);
276 }
277
278 static void
279 eng_gradient2_linear_render_post(void *data __UNUSED__, void *linear_gradient __UNUSED__)
280 {
281 }
282
283 static void
284 eng_gradient2_linear_draw(void *data __UNUSED__, void *context, void *surface, void *linear_gradient, int x, int y, int w, int h)
285 {
286 #ifdef BUILD_PIPE_RENDER
287    if (cpunum > 1)
288      evas_common_pipe_grad2_draw(surface, context, x, y, w, h, linear_gradient);
289    else
290 #endif
291      evas_common_gradient2_draw(surface, context, x, y, w, h, linear_gradient);
292 }
293
294 static void *
295 eng_gradient2_radial_new(void *data __UNUSED__)
296 {
297    return evas_common_gradient2_radial_new();
298 }
299
300 static void
301 eng_gradient2_radial_free(void *data __UNUSED__, void *radial_gradient)
302 {
303    evas_common_gradient2_free(radial_gradient);
304 }
305
306 static void
307 eng_gradient2_radial_fill_set(void *data __UNUSED__, void *radial_gradient, float cx, float cy, float rx, float ry)
308 {
309    evas_common_gradient2_radial_fill_set(radial_gradient, cx, cy, rx, ry);
310 }
311
312 static int
313 eng_gradient2_radial_is_opaque(void *data __UNUSED__, void *context, void *radial_gradient, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
314 {
315    RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
316    RGBA_Gradient2 *gr = (RGBA_Gradient2 *)radial_gradient;
317
318    if (!dc || !gr || !gr->type.geometer)  return 0;
319    return !(gr->type.geometer->has_alpha(gr, dc->render_op) |
320               gr->type.geometer->has_mask(gr, dc->render_op));
321 }
322
323 static int
324 eng_gradient2_radial_is_visible(void *data __UNUSED__, void *context, void *radial_gradient, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
325 {
326    RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
327
328    if (!dc || !radial_gradient)  return 0;
329    return 1;
330 }
331
332 static void
333 eng_gradient2_radial_render_pre(void *data __UNUSED__, void *context, void *radial_gradient)
334 {
335    RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
336    RGBA_Gradient2 *gr = (RGBA_Gradient2 *)radial_gradient;
337    int  len;
338
339    if (!dc || !gr || !gr->type.geometer)  return;
340    gr->type.geometer->geom_update(gr);
341    len = gr->type.geometer->get_map_len(gr);
342    evas_common_gradient2_map(dc, gr, len);
343 }
344
345 static void
346 eng_gradient2_radial_render_post(void *data __UNUSED__, void *radial_gradient __UNUSED__)
347 {
348 }
349
350 static void
351 eng_gradient2_radial_draw(void *data __UNUSED__, void *context, void *surface, void *radial_gradient, int x, int y, int w, int h)
352 {
353 #ifdef BUILD_PIPE_RENDER
354    if (cpunum > 1)
355      evas_common_pipe_grad2_draw(surface, context, x, y, w, h, radial_gradient);
356    else
357 #endif
358      evas_common_gradient2_draw(surface, context, x, y, w, h, radial_gradient);
359 }
360
361 static void *
362 eng_gradient_new(void *data __UNUSED__)
363 {
364    return evas_common_gradient_new();
365 }
366
367 static void
368 eng_gradient_free(void *data __UNUSED__, void *gradient)
369 {
370    evas_common_gradient_free(gradient);
371 }
372
373 static void
374 eng_gradient_color_stop_add(void *data __UNUSED__, void *gradient, int r, int g, int b, int a, int delta)
375 {
376    evas_common_gradient_color_stop_add(gradient, r, g, b, a, delta);
377 }
378
379 static void
380 eng_gradient_alpha_stop_add(void *data __UNUSED__, void *gradient, int a, int delta)
381 {
382    evas_common_gradient_alpha_stop_add(gradient, a, delta);
383 }
384
385 static void
386 eng_gradient_color_data_set(void *data __UNUSED__, void *gradient, void *map, int len, int has_alpha)
387 {
388    evas_common_gradient_color_data_set(gradient, map, len, has_alpha);
389 }
390
391 static void
392 eng_gradient_alpha_data_set(void *data __UNUSED__, void *gradient, void *alpha_map, int len)
393 {
394    evas_common_gradient_alpha_data_set(gradient, alpha_map, len);
395 }
396
397 static void
398 eng_gradient_clear(void *data __UNUSED__, void *gradient)
399 {
400    evas_common_gradient_clear(gradient);
401 }
402
403 static void
404 eng_gradient_fill_set(void *data __UNUSED__, void *gradient, int x, int y, int w, int h)
405 {
406    evas_common_gradient_fill_set(gradient, x, y, w, h);
407 }
408
409 static void
410 eng_gradient_fill_angle_set(void *data __UNUSED__, void *gradient, double angle)
411 {
412    evas_common_gradient_fill_angle_set(gradient, angle);
413 }
414
415 static void
416 eng_gradient_fill_spread_set(void *data __UNUSED__, void *gradient, int spread)
417 {
418    evas_common_gradient_fill_spread_set(gradient, spread);
419 }
420
421 static void
422 eng_gradient_angle_set(void *data __UNUSED__, void *gradient, double angle)
423 {
424    evas_common_gradient_map_angle_set(gradient, angle);
425 }
426
427 static void
428 eng_gradient_offset_set(void *data __UNUSED__, void *gradient, float offset)
429 {
430    evas_common_gradient_map_offset_set(gradient, offset);
431 }
432
433 static void
434 eng_gradient_direction_set(void *data __UNUSED__, void *gradient, int direction)
435 {
436    evas_common_gradient_map_direction_set(gradient, direction);
437 }
438
439 static void
440 eng_gradient_type_set(void *data __UNUSED__, void *gradient, char *name, char *params)
441 {
442    evas_common_gradient_type_set(gradient, name, params);
443 }
444
445 static int
446 eng_gradient_is_opaque(void *data __UNUSED__, void *context, void *gradient, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
447 {
448    RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
449    RGBA_Gradient *gr = (RGBA_Gradient *)gradient;
450
451    if (!dc || !gr || !gr->type.geometer)  return 0;
452    return !(gr->type.geometer->has_alpha(gr, dc->render_op) |
453               gr->type.geometer->has_mask(gr, dc->render_op));
454 }
455
456 static int
457 eng_gradient_is_visible(void *data __UNUSED__, void *context, void *gradient, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
458 {
459    RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
460
461    if (!dc || !gradient)  return 0;
462    return 1;
463 }
464
465 static void
466 eng_gradient_render_pre(void *data __UNUSED__, void *context, void *gradient)
467 {
468    RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
469    RGBA_Gradient *gr = (RGBA_Gradient *)gradient;
470    int  len;
471
472    if (!dc || !gr || !gr->type.geometer)  return;
473    gr->type.geometer->geom_set(gr);
474    len = gr->type.geometer->get_map_len(gr);
475    evas_common_gradient_map(dc, gr, len);
476 }
477
478 static void
479 eng_gradient_render_post(void *data __UNUSED__, void *gradient __UNUSED__)
480 {
481 }
482
483 static void
484 eng_gradient_draw(void *data __UNUSED__, void *context, void *surface, void *gradient, int x, int y, int w, int h)
485 {
486 #ifdef BUILD_PIPE_RENDER
487    if (cpunum > 1)
488      evas_common_pipe_grad_draw(surface, context, x, y, w, h, gradient);
489    else
490 #endif   
491      {
492         evas_common_gradient_draw(surface, context, x, y, w, h, gradient);
493         evas_common_cpu_end_opt();
494      }
495 }
496
497 static int
498 eng_image_alpha_get(void *data __UNUSED__, void *image)
499 {
500    Image_Entry *im;
501
502    if (!image) return 1;
503    im = image;
504    switch (im->space)
505      {
506       case EVAS_COLORSPACE_ARGB8888:
507         if (im->flags.alpha) return 1;
508       default:
509         break;
510      }
511    return 0;
512 }
513
514 static int
515 eng_image_colorspace_get(void *data __UNUSED__, void *image)
516 {
517    Image_Entry *im;
518
519    if (!image) return EVAS_COLORSPACE_ARGB8888;
520    im = image;
521    return im->space;
522 }
523
524 static void *
525 eng_image_alpha_set(void *data __UNUSED__, void *image, int has_alpha)
526 {
527    RGBA_Image *im;
528
529    if (!image) return NULL;
530    im = image;
531    if (im->cache_entry.space != EVAS_COLORSPACE_ARGB8888)
532      {
533         im->cache_entry.flags.alpha = 0;
534         return im;
535      }
536    im = (RGBA_Image *) evas_cache_image_alone(&im->cache_entry);
537    evas_common_image_colorspace_dirty(im);
538
539    im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
540    return im;
541 }
542
543 static void *
544 eng_image_border_set(void *data __UNUSED__, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
545 {
546    RGBA_Image *im;
547
548    im = image;
549    return im;
550 }
551
552 static void
553 eng_image_border_get(void *data __UNUSED__, void *image, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
554 {
555    RGBA_Image *im;
556
557    im = image;
558 }
559
560 static char *
561 eng_image_comment_get(void *data __UNUSED__, void *image, char *key __UNUSED__)
562 {
563    RGBA_Image *im;
564
565    if (!image) return NULL;
566    im = image;
567    return im->info.comment;
568 }
569
570 static char *
571 eng_image_format_get(void *data __UNUSED__, void *image __UNUSED__)
572 {
573    return NULL;
574 }
575
576 static void
577 eng_image_colorspace_set(void *data __UNUSED__, void *image, int cspace)
578 {
579    Image_Entry *im;
580
581    if (!image) return;
582    im = image;
583    evas_cache_image_colorspace(im, cspace);
584 }
585
586 static void
587 eng_image_native_set(void *data __UNUSED__, void *image __UNUSED__, void *native __UNUSED__)
588 {
589 }
590
591 static void *
592 eng_image_native_get(void *data __UNUSED__, void *image __UNUSED__)
593 {
594    return NULL;
595 }
596
597 static void *
598 eng_image_load(void *data __UNUSED__, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
599 {
600    *error = EVAS_LOAD_ERROR_NONE;
601    return evas_common_load_image_from_file(file, key, lo, error);
602 }
603
604 static void *
605 eng_image_new_from_data(void *data __UNUSED__, int w, int h, DATA32 *image_data, int alpha, int cspace)
606 {
607    return evas_cache_image_data(evas_common_image_cache_get(), w, h, image_data, alpha, cspace);
608 }
609
610 static void *
611 eng_image_new_from_copied_data(void *data __UNUSED__, int w, int h, DATA32 *image_data, int alpha, int cspace)
612 {
613    return evas_cache_image_copied_data(evas_common_image_cache_get(), w, h, image_data, alpha, cspace);
614 }
615
616 static void
617 eng_image_free(void *data __UNUSED__, void *image)
618 {
619    evas_cache_image_drop(image);
620 }
621
622 static void
623 eng_image_size_get(void *data __UNUSED__, void *image, int *w, int *h)
624 {
625    Image_Entry *im;
626
627    im = image;
628    if (w) *w = im->w;
629    if (h) *h = im->h;
630 }
631
632 static void *
633 eng_image_size_set(void *data __UNUSED__, void *image, int w, int h)
634 {
635    Image_Entry *im;
636
637    im = image;
638    return evas_cache_image_size_set(image, w, h);
639 }
640
641 static void *
642 eng_image_dirty_region(void *data __UNUSED__, void *image, int x, int y, int w, int h)
643 {
644    Image_Entry *im = image;
645
646    if (!image) return NULL;
647    return evas_cache_image_dirty(im, x, y, w, h);
648 }
649
650 static void *
651 eng_image_data_get(void *data __UNUSED__, void *image, int to_write, DATA32 **image_data)
652 {
653    RGBA_Image *im;
654
655    if (!image)
656      {
657         *image_data = NULL;
658         return NULL;
659      }
660    im = image;
661    evas_cache_image_load_data(&im->cache_entry);
662    switch (im->cache_entry.space)
663      {
664       case EVAS_COLORSPACE_ARGB8888:
665         if (to_write)
666           im = (RGBA_Image *) evas_cache_image_alone(&im->cache_entry);
667         *image_data = im->image.data;
668         break;
669       case EVAS_COLORSPACE_YCBCR422P601_PL:
670       case EVAS_COLORSPACE_YCBCR422P709_PL:
671         *image_data = im->cs.data;
672         break;
673       default:
674         abort();
675         break;
676      }
677    return im;
678 }
679
680 static void *
681 eng_image_data_put(void *data, void *image, DATA32 *image_data)
682 {
683    RGBA_Image *im, *im2;
684
685    if (!image) return NULL;
686    im = image;
687    switch (im->cache_entry.space)
688      {
689       case EVAS_COLORSPACE_ARGB8888:
690         if (image_data != im->image.data)
691           {
692              int w, h;
693
694              w = im->cache_entry.w;
695              h = im->cache_entry.h;
696              im2 = eng_image_new_from_data(data, w, h, image_data,
697                                            eng_image_alpha_get(data, image),
698                                            eng_image_colorspace_get(data, image));
699              evas_cache_image_drop(&im->cache_entry);
700              im = im2;
701           }
702         break;
703       case EVAS_COLORSPACE_YCBCR422P601_PL:
704       case EVAS_COLORSPACE_YCBCR422P709_PL:
705         if (image_data != im->cs.data)
706           {
707              if (im->cs.data)
708                {
709                   if (!im->cs.no_free) free(im->cs.data);
710                }
711              im->cs.data = image_data;
712              evas_common_image_colorspace_dirty(im);
713           }
714         break;
715       default:
716         abort();
717         break;
718      }
719    return im;
720 }
721
722 static void
723 eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
724 {
725    RGBA_Image *im = image;
726
727    if (!im) return ;
728    evas_cache_image_preload_data(&im->cache_entry, target);
729 }
730
731 static void
732 eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
733 {
734    RGBA_Image *im = image;
735
736    if (!im) return ;
737    evas_cache_image_preload_cancel(&im->cache_entry, target);
738 }
739
740 static void
741 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)
742 {
743    RGBA_Image *im;
744
745    if (!image) return;
746    im = image;
747 #ifdef BUILD_PIPE_RENDER
748    if (cpunum > 1)
749      {
750         evas_common_rgba_image_scalecache_prepare(im, surface, context, smooth,
751                                                   src_x, src_y, src_w, src_h,
752                                                   dst_x, dst_y, dst_w, dst_h);
753         
754         evas_common_pipe_image_draw(im, surface, context, smooth,
755                                     src_x, src_y, src_w, src_h,
756                                     dst_x, dst_y, dst_w, dst_h);
757      }
758    else
759 #endif
760      {
761 //        if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
762 //          evas_cache_image_load_data(&im->cache_entry);
763 //        evas_common_image_colorspace_normalize(im);
764         evas_common_rgba_image_scalecache_prepare(&im->cache_entry, surface, context, smooth,
765                                                   src_x, src_y, src_w, src_h,
766                                                   dst_x, dst_y, dst_w, dst_h);
767         evas_common_rgba_image_scalecache_do(&im->cache_entry, surface, context, smooth,
768                                              src_x, src_y, src_w, src_h,
769                                              dst_x, dst_y, dst_w, dst_h);
770 /*        
771         if (smooth)
772           evas_common_scale_rgba_in_to_out_clip_smooth(im, surface, context,
773                                                        src_x, src_y, src_w, src_h,
774                                                        dst_x, dst_y, dst_w, dst_h);
775         else
776           evas_common_scale_rgba_in_to_out_clip_sample(im, surface, context,
777                                                        src_x, src_y, src_w, src_h,
778                                                        dst_x, dst_y, dst_w, dst_h);
779  */
780         evas_common_cpu_end_opt();
781      }
782 }
783
784 static void
785 eng_image_map4_draw(void *data __UNUSED__, void *context, void *surface, void *image, RGBA_Map_Point *p, int smooth, int level)
786 {
787    RGBA_Image *im, *srf;
788    RGBA_Map_Point *pt = p;
789
790    if (!image) return;
791    im = image;
792    srf = surface;
793    if ((p[0].x == p[3].x) &&
794        (p[1].x == p[2].x) &&
795        (p[0].y == p[1].y) &&
796        (p[3].y == p[2].y) &&
797        (p[0].x <= p[1].x) &&
798        (p[0].y <= p[2].y) &&
799        (p[0].u == 0) &&
800        (p[0].v == 0) &&
801        (p[1].u == (im->cache_entry.w << FP)) &&
802        (p[1].v == 0) &&
803        (p[2].u == (im->cache_entry.w << FP)) &&
804        (p[2].v == (im->cache_entry.h << FP)) &&
805        (p[3].u == 0) &&
806        (p[3].v == (im->cache_entry.h << FP)) &&
807        (p[0].col == 0xffffffff) &&
808        (p[1].col == 0xffffffff) &&
809        (p[2].col == 0xffffffff) &&
810        (p[3].col == 0xffffffff))
811      {
812         int dx, dy, dw, dh;
813         
814         dx = p[0].x >> FP;
815         dy = p[0].y >> FP;
816         dw = (p[2].x >> FP) - dx;
817         dh = (p[2].y >> FP) - dy;
818         eng_image_draw
819           (data, context, surface, image,
820            0, 0, im->cache_entry.w, im->cache_entry.h,
821            dx, dy, dw, dh, smooth);
822      }
823    else
824      {
825 #ifdef BUILD_PIPE_RENDER
826         if (cpunum > 1)
827           evas_common_pipe_map4_draw(im, surface, context, p, smooth, level);
828         else
829 #endif
830           evas_common_map4_rgba(im, surface, context, p, smooth, level);
831      }
832    evas_common_cpu_end_opt();
833 }
834
835 static void *
836 eng_image_map_surface_new(void *data __UNUSED__, int w, int h, int alpha)
837 {
838    void *surface;
839    DATA32 *pixels;
840    surface = evas_cache_image_copied_data(evas_common_image_cache_get(), 
841                                           w, h, NULL, alpha, 
842                                           EVAS_COLORSPACE_ARGB8888);
843    pixels = evas_cache_image_pixels(surface);
844    return surface;
845 }
846
847 static void
848 eng_image_map_surface_free(void *data __UNUSED__, void *surface)
849 {
850    evas_cache_image_drop(surface);
851 }
852
853 static void
854 eng_image_scale_hint_set(void *data __UNUSED__, void *image, int hint)
855 {
856    Image_Entry *im;
857
858    if (!image) return;
859    im = image;
860    im->scale_hint = hint;
861 }
862
863 static int
864 eng_image_scale_hint_get(void *data __UNUSED__, void *image)
865 {
866    Image_Entry *im;
867
868    if (!image) return EVAS_IMAGE_SCALE_HINT_NONE;
869    im = image;
870    return im->scale_hint;
871 }
872
873 static void
874 eng_image_cache_flush(void *data __UNUSED__)
875 {
876    int tmp_size;
877
878    tmp_size = evas_common_image_get_cache();
879    evas_common_image_set_cache(0);
880    evas_common_rgba_image_scalecache_flush();
881    evas_common_image_set_cache(tmp_size);
882 }
883
884 static void
885 eng_image_cache_set(void *data __UNUSED__, int bytes)
886 {
887    evas_common_image_set_cache(bytes);
888    evas_common_rgba_image_scalecache_size_set(bytes);
889 }
890
891 static int
892 eng_image_cache_get(void *data __UNUSED__)
893 {
894    return evas_common_image_get_cache();
895 }
896
897 static void *
898 eng_font_load(void *data __UNUSED__, const char *name, int size)
899 {
900    return evas_common_font_load(name, size);
901 }
902
903 static void *
904 eng_font_memory_load(void *data __UNUSED__, char *name, int size, const void *fdata, int fdata_size)
905 {
906    return evas_common_font_memory_load(name, size, fdata, fdata_size);
907 }
908
909 static void *
910 eng_font_add(void *data __UNUSED__, void *font, const char *name, int size)
911 {
912    return evas_common_font_add(font, name, size);
913 }
914
915 static void *
916 eng_font_memory_add(void *data __UNUSED__, void *font, char *name, int size, const void *fdata, int fdata_size)
917 {
918    return evas_common_font_memory_add(font, name, size, fdata, fdata_size);
919 }
920
921 static void
922 eng_font_free(void *data __UNUSED__, void *font)
923 {
924    evas_common_font_free(font);
925 }
926
927 static int
928 eng_font_ascent_get(void *data __UNUSED__, void *font)
929 {
930    return evas_common_font_ascent_get(font);
931 }
932
933 static int
934 eng_font_descent_get(void *data __UNUSED__, void *font)
935 {
936    return evas_common_font_descent_get(font);
937 }
938
939 static int
940 eng_font_max_ascent_get(void *data __UNUSED__, void *font)
941 {
942    return evas_common_font_max_ascent_get(font);
943 }
944
945 static int
946 eng_font_max_descent_get(void *data __UNUSED__, void *font)
947 {
948    return evas_common_font_max_descent_get(font);
949 }
950
951 static void
952 eng_font_string_size_get(void *data __UNUSED__, void *font, const char *text, int *w, int *h)
953 {
954    evas_common_font_query_size(font, text, w, h);
955 }
956
957 static int
958 eng_font_inset_get(void *data __UNUSED__, void *font, const char *text)
959 {
960    return evas_common_font_query_inset(font, text);
961 }
962
963 static int
964 eng_font_h_advance_get(void *data __UNUSED__, void *font, const char *text)
965 {
966    int h, v;
967
968    evas_common_font_query_advance(font, text, &h, &v);
969    return h;
970 }
971
972 static int
973 eng_font_v_advance_get(void *data __UNUSED__, void *font, const char *text)
974 {
975    int h, v;
976
977    evas_common_font_query_advance(font, text, &h, &v);
978    return v;
979 }
980
981 static int
982 eng_font_char_coords_get(void *data __UNUSED__, void *font, const char *text, int pos, int *cx, int *cy, int *cw, int *ch)
983 {
984    return evas_common_font_query_char_coords(font, text, pos, cx, cy, cw, ch);
985 }
986
987 static int
988 eng_font_char_at_coords_get(void *data __UNUSED__, void *font, const char *text, int x, int y, int *cx, int *cy, int *cw, int *ch)
989 {
990    return evas_common_font_query_text_at_pos(font, text, x, y, cx, cy, cw, ch);
991 }
992
993 static int
994 eng_font_last_up_to_pos(void *data __UNUSED__, void *font, const char *text, int x, int y)
995 {
996    return evas_common_font_query_last_up_to_pos(font, text, x, y);
997 }
998
999 static void
1000 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 char *text)
1001 {
1002 #ifdef BUILD_PIPE_RENDER
1003    if (cpunum > 1)
1004      evas_common_pipe_text_draw(surface, context, font, x, y, text);
1005    else
1006 #endif   
1007      {
1008         evas_common_font_draw(surface, context, font, x, y, text);
1009         evas_common_cpu_end_opt();
1010      }
1011 }
1012
1013 static void
1014 eng_font_cache_flush(void *data __UNUSED__)
1015 {
1016    evas_common_font_flush();
1017 }
1018
1019 static void
1020 eng_font_cache_set(void *data __UNUSED__, int bytes)
1021 {
1022    evas_common_font_cache_set(bytes);
1023 }
1024
1025 static int
1026 eng_font_cache_get(void *data __UNUSED__)
1027 {
1028    return evas_common_font_cache_get();
1029 }
1030
1031 static void
1032 eng_font_hinting_set(void *data __UNUSED__, void *font, int hinting)
1033 {
1034    evas_common_font_hinting_set(font, hinting);
1035 }
1036
1037 static int
1038 eng_font_hinting_can_hint(void *data __UNUSED__, int hinting)
1039 {
1040    return evas_common_hinting_available(hinting);
1041 }
1042
1043 static Eina_Bool
1044 eng_canvas_alpha_get(void *data __UNUSED__, void *info __UNUSED__)
1045 {
1046    return EINA_TRUE;
1047 }
1048
1049 /*
1050  *****
1051  **
1052  ** ENGINE API
1053  **
1054  *****
1055  */
1056
1057 static Evas_Func func =
1058 {
1059    NULL,
1060      NULL,
1061      NULL,
1062      NULL,
1063      NULL,
1064      NULL,
1065      NULL,
1066      NULL,
1067      NULL,
1068      NULL,
1069      NULL,
1070      NULL,
1071      NULL,
1072      eng_output_dump,
1073      /* draw context virtual methods */
1074      eng_context_new,
1075      eng_canvas_alpha_get,
1076      eng_context_free,
1077      eng_context_clip_set,
1078      eng_context_clip_clip,
1079      eng_context_clip_unset,
1080      eng_context_clip_get,
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      /* gradient draw funcs */
1103      eng_gradient2_color_np_stop_insert,
1104      eng_gradient2_clear,
1105      eng_gradient2_fill_transform_set,
1106      eng_gradient2_fill_spread_set,
1107
1108      eng_gradient2_linear_new,
1109      eng_gradient2_linear_free,
1110      eng_gradient2_linear_fill_set,
1111      eng_gradient2_linear_is_opaque,
1112      eng_gradient2_linear_is_visible,
1113      eng_gradient2_linear_render_pre,
1114      eng_gradient2_linear_render_post,
1115      eng_gradient2_linear_draw,
1116
1117      eng_gradient2_radial_new,
1118      eng_gradient2_radial_free,
1119      eng_gradient2_radial_fill_set,
1120      eng_gradient2_radial_is_opaque,
1121      eng_gradient2_radial_is_visible,
1122      eng_gradient2_radial_render_pre,
1123      eng_gradient2_radial_render_post,
1124      eng_gradient2_radial_draw,
1125
1126      eng_gradient_new,
1127      eng_gradient_free,
1128      eng_gradient_color_stop_add,
1129      eng_gradient_alpha_stop_add,
1130      eng_gradient_color_data_set,
1131      eng_gradient_alpha_data_set,
1132      eng_gradient_clear,
1133      eng_gradient_fill_set,
1134      eng_gradient_fill_angle_set,
1135      eng_gradient_fill_spread_set,
1136      eng_gradient_angle_set,
1137      eng_gradient_offset_set,
1138      eng_gradient_direction_set,
1139      eng_gradient_type_set,
1140      eng_gradient_is_opaque,
1141      eng_gradient_is_visible,
1142      eng_gradient_render_pre,
1143      eng_gradient_render_post,
1144      eng_gradient_draw,
1145      /* image draw funcs */
1146      eng_image_load,
1147      eng_image_new_from_data,
1148      eng_image_new_from_copied_data,
1149      eng_image_free,
1150      eng_image_size_get,
1151      eng_image_size_set,
1152      NULL,
1153      eng_image_dirty_region,
1154      eng_image_data_get,
1155      eng_image_data_put,
1156      eng_image_data_preload_request,
1157      eng_image_data_preload_cancel,
1158      eng_image_alpha_set,
1159      eng_image_alpha_get,
1160      eng_image_border_set,
1161      eng_image_border_get,
1162      eng_image_draw,
1163      eng_image_comment_get,
1164      eng_image_format_get,
1165      eng_image_colorspace_set,
1166      eng_image_colorspace_get,
1167      eng_image_native_set,
1168      eng_image_native_get,
1169      /* image cache funcs */
1170      eng_image_cache_flush,
1171      eng_image_cache_set,
1172      eng_image_cache_get,
1173      /* font draw functions */
1174      eng_font_load,
1175      eng_font_memory_load,
1176      eng_font_add,
1177      eng_font_memory_add,
1178      eng_font_free,
1179      eng_font_ascent_get,
1180      eng_font_descent_get,
1181      eng_font_max_ascent_get,
1182      eng_font_max_descent_get,
1183      eng_font_string_size_get,
1184      eng_font_inset_get,
1185      eng_font_h_advance_get,
1186      eng_font_v_advance_get,
1187      eng_font_char_coords_get,
1188      eng_font_char_at_coords_get,
1189      eng_font_draw,
1190      /* font cache functions */
1191      eng_font_cache_flush,
1192      eng_font_cache_set,
1193      eng_font_cache_get,
1194      /* font hinting functions */
1195      eng_font_hinting_set,
1196      eng_font_hinting_can_hint,
1197      eng_image_scale_hint_set,
1198      eng_image_scale_hint_get,
1199      /* more font draw functions */
1200      eng_font_last_up_to_pos,
1201      /* FUTURE software generic calls go here (done) */
1202      eng_image_map4_draw,
1203      eng_image_map_surface_new,
1204      eng_image_map_surface_free
1205      /* FUTURE software generic calls go here */
1206 };
1207
1208 /*
1209  *****
1210  **
1211  ** MODULE ACCESSIBLE API API
1212  **
1213  *****
1214  */
1215
1216 static int
1217 module_open(Evas_Module *em)
1218 {
1219    if (!em) return 0;
1220    _evas_soft_gen_log_dom = eina_log_domain_register("EvasSoftGeneric", EVAS_DEFAULT_LOG_COLOR);
1221    if(_evas_soft_gen_log_dom<0)
1222      {
1223        EINA_LOG_ERR("Evas SoftGen : Impossible to create a log domain for the software generic engine.\n");
1224        return 0;
1225      }
1226    em->functions = (void *)(&func);
1227    cpunum = eina_cpu_count();
1228    return 1;
1229 }
1230
1231 static void
1232 module_close(Evas_Module *em)
1233 {
1234   eina_log_domain_unregister(_evas_soft_gen_log_dom);
1235 }
1236
1237 static Evas_Module_Api evas_modapi =
1238 {
1239    EVAS_MODULE_API_VERSION,
1240    "software_generic",
1241    "none",
1242    {
1243      module_open,
1244      module_close
1245    }
1246 };
1247
1248 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, software_generic);
1249
1250 #ifndef EVAS_STATIC_BUILD_SOFTWARE_GENERIC
1251 EVAS_EINA_MODULE_DEFINE(engine, software_generic);
1252 #endif