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