* evas_cache_image: Attempt to make a definitiv fix for race condition on cancel.
[profile/ivi/evas.git] / src / lib / include / evas_common.h
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #ifndef EVAS_COMMON_H
6 #define EVAS_COMMON_H
7
8 #ifdef HAVE_CONFIG_H
9 # include "config.h"  /* so that EAPI in Evas.h is correctly defined */
10 #endif
11
12 #include <Eina.h>
13 #include "Evas.h"
14
15 /* macros needed to log message through eina_log */
16 extern EAPI int _evas_log_dom_global;
17 #ifdef  _EVAS_DEFAULT_LOG_DOM
18 # undef _EVAS_DEFAULT_LOG_DOM
19 #endif
20 #define _EVAS_DEFAULT_LOG_DOM _evas_log_dom_global
21
22 #ifdef EVAS_DEFAULT_LOG_COLOR
23 # undef EVAS_DEFAULT_LOG_COLOR
24 #endif
25 #define EVAS_DEFAULT_LOG_COLOR EINA_COLOR_BLUE
26
27 #ifdef ERR
28 # undef ERR
29 #endif
30 #define ERR(...) EINA_LOG_DOM_ERR(_EVAS_DEFAULT_LOG_DOM, __VA_ARGS__)
31
32 #ifdef DBG
33 # undef DBG
34 #endif
35 #define DBG(...) EINA_LOG_DOM_DBG(_EVAS_DEFAULT_LOG_DOM, __VA_ARGS__)
36
37 #ifdef INF
38 # undef INF
39 #endif
40 #define INF(...) EINA_LOG_DOM_INFO(_EVAS_DEFAULT_LOG_DOM, __VA_ARGS__)
41
42 #ifdef WRN
43 # undef WRN
44 #endif
45 #define WRN(...) EINA_LOG_DOM_WARN(_EVAS_DEFAULT_LOG_DOM, __VA_ARGS__)
46
47 #ifdef CRIT
48 # undef CRIT
49 #endif
50 #define CRIT(...) EINA_LOG_DOM_CRIT(_EVAS_DEFAULT_LOG_DOM, __VA_ARGS__)
51
52 /*****************************************************************************/
53
54 #include "evas_options.h"
55
56 #if defined(__ARM_ARCH_3M__)
57 # define __ARM_ARCH__ 40
58 #endif
59 #if defined(__ARM_ARCH_4__)
60 # define __ARM_ARCH__ 40
61 #endif
62 #if defined(__ARM_ARCH_4T__)
63 # define __ARM_ARCH__ 41
64 #endif
65
66 #if defined(__ARM_ARCH_5__)
67 # define __ARM_ARCH__ 50
68 #endif
69 #if defined(__ARM_ARCH_5T__)
70 # define __ARM_ARCH__ 51
71 #endif
72 #if defined(__ARM_ARCH_5E__)
73 # define __ARM_ARCH__ 52
74 #endif
75 #if defined(__ARM_ARCH_5TE__)
76 # define __ARM_ARCH__ 53
77 #endif
78 #if defined(__ARM_ARCH_5TEJ__)
79 # define __ARM_ARCH__ 54
80 #endif
81
82 #if defined(__ARM_ARCH_6__)
83 # define __ARM_ARCH__ 60
84 #endif
85 #if defined(__ARM_ARCH_6J__)
86 # define __ARM_ARCH__ 61
87 #endif
88 #if defined(__ARM_ARCH_6K__)
89 # define __ARM_ARCH__ 62
90 #endif
91 #if defined(__ARM_ARCH_6Z__)
92 # define __ARM_ARCH__ 63
93 #endif
94 #if defined(__ARM_ARCH_6ZK__)
95 # define __ARM_ARCH__ 64
96 #endif
97 #if defined(__ARM_ARCH_6T2__)
98 # define __ARM_ARCH__ 65
99 #endif
100
101 #if defined(__ARM_ARCH_7__)
102 # define __ARM_ARCH__ 70
103 #endif
104 #if defined(__ARM_ARCH_7A__)
105 # define __ARM_ARCH__ 71
106 #endif
107 #if defined(__ARM_ARCH_7R__)
108 # define __ARM_ARCH__ 72
109 #endif
110 #if defined(__ARM_ARCH_7M__)
111 # define __ARM_ARCH__ 73
112 #endif
113
114 #ifndef _GNU_SOURCE
115 # define _GNU_SOURCE
116 #endif
117
118 #ifndef BUILD_PTHREAD
119 # undef BUILD_PIPE_RENDER
120 #endif
121
122 #ifdef BUILD_PTHREAD
123
124 #ifndef __USE_GNU
125 #define __USE_GNU
126 #endif
127
128 # include <pthread.h>
129 # include <sched.h>
130 # define LK(x)  pthread_mutex_t x
131 # define LKI(x) pthread_mutex_init(&(x), NULL);
132 # define LKD(x) pthread_mutex_destroy(&(x));
133 # define LKL(x) pthread_mutex_lock(&(x));
134 # define LKT(x) pthread_mutex_trylock(&(x));
135 # define LKU(x) pthread_mutex_unlock(&(x));
136 # define TH(x)  pthread_t x
137 # define THI(x) int x
138 # define TH_MAX 8
139
140 // even though in theory having every Nth rendered line done by a different
141 // thread might even out load across threads - it actually slows things down.
142 //#define EVAS_SLI 1
143
144 #else
145 # define LK(x)
146 # define LKI(x)
147 # define LKD(x)
148 # define LKL(x)
149 # define LKT(x) 0
150 # define LKU(x)
151 # define TH(x)
152 # define THI(x)
153 # define TH_MAX 0
154 #endif
155
156 #ifdef HAVE_ALLOCA_H
157 # include <alloca.h>
158 #elif defined __GNUC__
159 # define alloca __builtin_alloca
160 #elif defined _AIX
161 # define alloca __alloca
162 #elif defined _MSC_VER
163 # include <malloc.h>
164 # define alloca _alloca
165 #else
166 # include <stddef.h>
167 # ifdef  __cplusplus
168 extern "C"
169 # endif
170 void *alloca (size_t);
171 #endif
172
173 #include <stdio.h>
174 #include <stdlib.h>
175 #include <string.h>
176 #include <sys/types.h>
177 #include <sys/stat.h>
178 #include <time.h>
179 #include <ctype.h>
180 #ifndef _MSC_VER
181 # include <stdint.h>
182 # include <unistd.h>
183 #endif
184
185 #include <ft2build.h>
186 #include FT_FREETYPE_H
187 #include FT_GLYPH_H
188 #include FT_SIZES_H
189 #include FT_MODULE_H
190
191 #ifdef __GNUC__
192 # if __GNUC__ >= 4
193 // BROKEN in gcc 4 on amd64
194 //#  pragma GCC visibility push(hidden)
195 # endif
196 #define LIKELY(x)   __builtin_expect(!!(x), 1)
197 #define UNLIKELY(x) __builtin_expect(!!(x), 0)
198 #else
199 #define LIKELY(x)   (x)
200 #define UNLIKELY(x) (x)
201 #endif
202
203 /*****************************************************************************/
204
205 /* use exact rects for updates not tiles */
206 /* #define RECTUPDATE */
207 #define TILESIZE 8
208 #define IMG_MAX_SIZE 65000
209
210 #define IMG_TOO_BIG(w, h) \
211    ((((unsigned long long)w) * ((unsigned long long)h)) >= \
212        ((1ULL << (29 * (sizeof(void *) / 4))) - 2048))
213
214 #ifdef BUILD_SMALL_DITHER_MASK
215 # define DM_TABLE     _evas_dither_44
216 # define DM_SIZE      4
217 # define DM_BITS      4
218 # define DM_DIV       16
219 # define USE_DITHER_44 1
220 # define DM_MSK       (DM_SIZE - 1)
221 # define DM_SHF(_b)   (DM_BITS - (8 - _b))
222 #else
223 # define DM_TABLE     _evas_dither_128128
224 # define DM_SIZE      128
225 # define DM_BITS      6
226 # define DM_DIV       64
227 # define USE_DITHER_128128 1
228 # define DM_MSK       (DM_SIZE - 1)
229 # define DM_SHF(_b)   (DM_BITS - (8 - _b))
230 #endif
231
232 /* if more than 1/ALPHA_SPARSE_INV_FRACTION is "alpha" (1-254) then sparse
233  * alpha flag gets set */
234 #define ALPHA_SPARSE_INV_FRACTION 3
235
236 /*****************************************************************************/
237
238 #if defined(__ARM_ARCH_3M__)
239 # define __ARM_ARCH__ 40
240 #endif
241 #if defined(__ARM_ARCH_4__)
242 # define __ARM_ARCH__ 40
243 #endif
244 #if defined(__ARM_ARCH_4T__)
245 # define __ARM_ARCH__ 41
246 #endif
247
248 #if defined(__ARM_ARCH_5__)
249 # define __ARM_ARCH__ 50
250 #endif
251 #if defined(__ARM_ARCH_5T__)
252 # define __ARM_ARCH__ 51
253 #endif
254 #if defined(__ARM_ARCH_5E__)
255 # define __ARM_ARCH__ 52
256 #endif
257 #if defined(__ARM_ARCH_5TE__)
258 # define __ARM_ARCH__ 53
259 #endif
260 #if defined(__ARM_ARCH_5TEJ__)
261 # define __ARM_ARCH__ 54
262 #endif
263
264 #if defined(__ARM_ARCH_6__)
265 # define __ARM_ARCH__ 60
266 #endif
267 #if defined(__ARM_ARCH_6J__)
268 # define __ARM_ARCH__ 61
269 #endif
270 #if defined(__ARM_ARCH_6K__)
271 # define __ARM_ARCH__ 62
272 #endif
273 #if defined(__ARM_ARCH_6Z__)
274 # define __ARM_ARCH__ 63
275 #endif
276 #if defined(__ARM_ARCH_6ZK__)
277 # define __ARM_ARCH__ 64
278 #endif
279 #if defined(__ARM_ARCH_6T2__)
280 # define __ARM_ARCH__ 65
281 #endif
282
283 #if defined(__ARM_ARCH_7__)
284 # define __ARM_ARCH__ 70
285 #endif
286 #if defined(__ARM_ARCH_7A__)
287 # define __ARM_ARCH__ 71
288 #endif
289 #if defined(__ARM_ARCH_7R__)
290 # define __ARM_ARCH__ 72
291 #endif
292 #if defined(__ARM_ARCH_7M__)
293 # define __ARM_ARCH__ 73
294 #endif
295
296 #if defined(__ARM_ARCH__) && (__ARM_ARCH__ >= 52)
297 /* tested on ARMv6 (arm1136j-s), Nokia N800 CPU */
298 #define pld(addr, off)                                                  \
299    __asm__("pld [%[address], %[offset]]"::                              \
300            [address] "r" (addr), [offset] "i" (off))
301 #else
302 #define pld(addr, off)
303 #endif /* __ARMEL__ */
304
305 /*****************************************************************************/
306
307 #define UNROLL2(op...) op op
308 #define UNROLL4(op...) UNROLL2(op) UNROLL2(op)
309 #define UNROLL8(op...) UNROLL4(op) UNROLL4(op)
310 #define UNROLL16(op...) UNROLL8(op) UNROLL8(op)
311
312 #define UNROLL8_PLD_WHILE(start, size, end, op)         \
313     pld(start, 0);                                      \
314     end = start + (size & ~7);                          \
315     while (start < end)                                 \
316         {                                               \
317             pld(start, 32);                             \
318             UNROLL8(op);                                \
319         }                                               \
320     end += (size & 7);                                  \
321     pld(start, 32);                                     \
322     while (start <  end)                                \
323         {                                               \
324         op;                                             \
325         }
326
327 /*****************************************************************************/
328
329 typedef unsigned long long              DATA64;
330 typedef unsigned int                    DATA32;
331 typedef unsigned short                  DATA16;
332 typedef unsigned char                   DATA8;
333
334 typedef struct _Image_Entry             Image_Entry;
335 typedef struct _Image_Entry_Flags       Image_Entry_Flags;
336 typedef struct _Engine_Image_Entry      Engine_Image_Entry;
337 typedef struct _Evas_Cache_Target       Evas_Cache_Target;
338
339 typedef struct _RGBA_Image_Loadopts   RGBA_Image_Loadopts;
340 #ifdef BUILD_PIPE_RENDER
341 typedef struct _RGBA_Pipe_Op          RGBA_Pipe_Op;
342 typedef struct _RGBA_Pipe             RGBA_Pipe;
343 typedef struct _RGBA_Pipe_Thread_Info RGBA_Pipe_Thread_Info;
344 #endif
345 typedef struct _RGBA_Image            RGBA_Image;
346 typedef struct _RGBA_Image_Span       RGBA_Image_Span;
347 typedef struct _RGBA_Draw_Context     RGBA_Draw_Context;
348 typedef struct _RGBA_Gradient         RGBA_Gradient;
349 typedef struct _RGBA_Gradient_Color_Stop   RGBA_Gradient_Color_Stop;
350 typedef struct _RGBA_Gradient_Alpha_Stop   RGBA_Gradient_Alpha_Stop;
351 typedef struct _RGBA_Gradient_Type    RGBA_Gradient_Type;
352 typedef struct _RGBA_Gradient2         RGBA_Gradient2;
353 typedef struct _RGBA_Gradient2_Type    RGBA_Gradient2_Type;
354 typedef struct _RGBA_Gradient2_Color_Np_Stop   RGBA_Gradient2_Color_Np_Stop;
355 typedef struct _RGBA_Polygon_Point    RGBA_Polygon_Point;
356 typedef struct _RGBA_Font             RGBA_Font;
357 typedef struct _RGBA_Font_Int         RGBA_Font_Int;
358 typedef struct _RGBA_Font_Source      RGBA_Font_Source;
359 typedef struct _RGBA_Font_Glyph       RGBA_Font_Glyph;
360 typedef struct _RGBA_Gfx_Compositor   RGBA_Gfx_Compositor;
361
362 typedef struct _Cutout_Rect           Cutout_Rect;
363 typedef struct _Cutout_Rects            Cutout_Rects;
364
365 typedef struct _Convert_Pal             Convert_Pal;
366
367 typedef struct _Tilebuf                 Tilebuf;
368 typedef struct _Tilebuf_Tile            Tilebuf_Tile;
369 typedef struct _Tilebuf_Rect            Tilebuf_Rect;
370
371 typedef struct _Evas_Common_Transform        Evas_Common_Transform;
372
373 /*
374 typedef struct _Regionbuf             Regionbuf;
375 typedef struct _Regionspan            Regionspan;
376 */
377
378 typedef void (*RGBA_Gfx_Func)    (DATA32 *src, DATA8 *mask, DATA32 col, DATA32 *dst, int len);
379 typedef void (*RGBA_Gfx_Pt_Func) (DATA32 src, DATA8 mask, DATA32 col, DATA32 *dst);
380 typedef void (*Gfx_Func_Copy)    (DATA32 *src, DATA32 *dst, int len);
381
382 typedef void (*Gfx_Func_Convert) (DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x, int dith_y, DATA8 *pal);
383
384 typedef void (*Gfx_Func_Gradient_Fill)(DATA32 *src, int src_len,
385                                          DATA32 *dst, DATA8 *mask, int len,
386                                          int x, int y, int axx, int axy, int ayx, int ayy,
387                                          void *geom_data);
388
389 typedef void (*Gfx_Func_Gradient2_Fill)(DATA32 *src, int src_len,
390                                          DATA32 *dst, DATA8 *mask, int len,
391                                          int x, int y,
392                                          void *geom_data);
393
394 #include "../cache/evas_cache.h"
395
396 /*****************************************************************************/
397
398 typedef enum _RGBA_Image_Flags
399 {
400    RGBA_IMAGE_NOTHING       = (0),
401 /*    RGBA_IMAGE_HAS_ALPHA     = (1 << 0), */
402    RGBA_IMAGE_IS_DIRTY      = (1 << 1),
403    RGBA_IMAGE_INDEXED       = (1 << 2),
404    RGBA_IMAGE_ALPHA_ONLY    = (1 << 3),
405    RGBA_IMAGE_ALPHA_TILES   = (1 << 4),
406 /*    RGBA_IMAGE_ALPHA_SPARSE  = (1 << 5), */
407 /*    RGBA_IMAGE_LOADED        = (1 << 6), */
408 /*    RGBA_IMAGE_NEED_DATA     = (1 << 7) */
409 } RGBA_Image_Flags;
410
411 typedef enum _Convert_Pal_Mode
412 {
413    PAL_MODE_NONE,
414    PAL_MODE_MONO,
415    PAL_MODE_GRAY4,
416    PAL_MODE_GRAY16,
417    PAL_MODE_GRAY64,
418    PAL_MODE_GRAY256,
419    PAL_MODE_RGB111,
420    PAL_MODE_RGB121,
421    PAL_MODE_RGB221,
422    PAL_MODE_RGB222,
423    PAL_MODE_RGB232,
424    PAL_MODE_RGB332,
425    PAL_MODE_RGB666,
426    PAL_MODE_LAST
427 } Convert_Pal_Mode;
428
429 typedef enum _CPU_Features
430 {
431    CPU_FEATURE_C       = 0,
432    CPU_FEATURE_MMX     = (1 << 0),
433    CPU_FEATURE_MMX2    = (1 << 1),
434    CPU_FEATURE_SSE     = (1 << 2),
435    CPU_FEATURE_ALTIVEC = (1 << 3),
436    CPU_FEATURE_VIS     = (1 << 4),
437    CPU_FEATURE_VIS2    = (1 << 5),
438    CPU_FEATURE_NEON    = (1 << 6)
439 } CPU_Features;
440
441 typedef enum _Font_Hint_Flags
442 {
443    FONT_NO_HINT,
444    FONT_AUTO_HINT,
445    FONT_BYTECODE_HINT
446 } Font_Hint_Flags;
447
448 /*****************************************************************************/
449
450 struct _RGBA_Image_Loadopts
451 {
452    int                  scale_down_by; // if > 1 then use this
453    double               dpi; // if > 0.0 use this
454    int                  w, h; // if > 0 use this
455    struct {
456       int               x, y, w, h;
457    } region;
458 };
459
460 struct _Image_Entry_Flags
461 {
462    Eina_Bool loaded       : 1;
463    Eina_Bool dirty        : 1;
464    Eina_Bool activ        : 1;
465    Eina_Bool need_data    : 1;
466    Eina_Bool lru_nodata   : 1;
467    Eina_Bool cached       : 1;
468    Eina_Bool alpha        : 1;
469    Eina_Bool alpha_sparse : 1;
470 #ifdef BUILD_ASYNC_PRELOAD
471    Eina_Bool preload      : 1;
472    Eina_Bool pending      : 1;
473    Eina_Bool in_pipe      : 1;
474 #endif
475 };
476
477 struct _Evas_Cache_Target
478 {
479   EINA_INLIST;
480   const void *target;
481 };
482
483 struct _Image_Entry
484 {
485    EINA_INLIST;
486
487    Evas_Cache_Image      *cache;
488
489    const char            *cache_key;
490
491    const char            *file;
492    const char            *key;
493
494    Evas_Cache_Target     *targets;
495
496    time_t                 timestamp;
497    time_t                 laststat;
498
499    int                    references;
500
501    unsigned char          scale;
502
503    RGBA_Image_Loadopts    load_opts;
504    int                    space;
505    int                    w;
506    int                    h;
507
508    struct
509      {
510         int              w;
511         int              h;
512      } allocated;
513
514    struct
515      {
516         void            *module;
517         void            *loader;
518      } info;
519
520 #ifdef BUILD_ASYNC_PRELOAD
521    LK(lock);
522 #endif
523
524    Image_Entry_Flags      flags;
525    Evas_Image_Scale_Hint  scale_hint;
526    void                  *data1, *data2;
527    int                    server_id;
528    int                    connect_num;
529    int                    channel;
530 };
531
532 struct _Engine_Image_Entry
533 {
534    EINA_INLIST;
535
536    /* Upper Engine data. */
537    Image_Entry                  *src;
538
539    /* Cache stuff. */
540    Evas_Cache_Engine_Image      *cache;
541    const char                   *cache_key;
542
543    struct
544    {
545      Eina_Bool                   cached : 1;
546      Eina_Bool                   activ : 1;
547      Eina_Bool                   dirty : 1;
548      Eina_Bool                   loaded : 1;
549      Eina_Bool                   need_parent : 1;
550    } flags;
551
552    int                           references;
553    int                           w;
554    int                           h;
555 };
556
557 struct _Cutout_Rect
558 {
559    int               x, y, w, h;
560 };
561
562 struct _Cutout_Rects
563 {
564    Cutout_Rect*      rects;
565    int               active;
566    int               max;
567 };
568
569 struct _Evas_Common_Transform
570 {
571    float  mxx, mxy, mxz;
572    float  myx, myy, myz;
573    float  mzx, mzy, mzz;
574 };
575
576 struct _RGBA_Draw_Context
577 {
578    struct {
579       Eina_Bool use : 1;
580       DATA32 col;
581    } mul;
582    struct {
583       DATA32 col;
584    } col;
585    struct RGBA_Draw_Context_clip {
586       int    x, y, w, h;
587       Eina_Bool use : 1;
588    } clip;
589    Cutout_Rects cutout;
590    struct {
591       struct {
592          void *(*gl_new)  (void *data, RGBA_Font_Glyph *fg);
593          void  (*gl_free) (void *ext_dat);
594          void  (*gl_draw) (void *data, void *dest, void *context, RGBA_Font_Glyph *fg, int x, int y);
595       } func;
596       void *data;
597    } font_ext;
598    struct {
599       int color_space;
600    } interpolation;
601    struct {
602       int y, h;
603    } sli;
604    int            render_op;
605    Eina_Bool anti_alias : 1;
606 };
607
608 #ifdef BUILD_PIPE_RENDER
609 struct _RGBA_Pipe_Op
610 {
611    RGBA_Draw_Context         context;
612    void                    (*op_func) (RGBA_Image *dst, RGBA_Pipe_Op *op, RGBA_Pipe_Thread_Info *info);
613    void                    (*free_func) (RGBA_Pipe_Op *op);
614
615    union {
616       struct {
617          int                 x, y, w, h;
618       } rect;
619       struct {
620          int                 x0, y0, x1, y1;
621       } line;
622       struct {
623          RGBA_Polygon_Point *points;
624       } poly;
625       struct {
626          RGBA_Gradient      *grad;
627          int                 x, y, w, h;
628       } grad;
629       struct {
630          RGBA_Gradient2      *grad;
631          int                 x, y, w, h;
632       } grad2;
633       struct {
634          RGBA_Font          *font;
635          int                 x, y;
636          char               *text;
637       } text;
638       struct {
639          RGBA_Image         *src;
640          int                 sx, sy, sw, sh, dx, dy, dw, dh;
641          int                 smooth;
642          char               *text;
643       } image;
644    } op;
645 };
646
647 #define PIPE_LEN 256
648
649 struct _RGBA_Pipe
650 {
651    EINA_INLIST;
652    int               op_num;
653    RGBA_Pipe_Op      op[PIPE_LEN];
654 };
655
656 struct _RGBA_Pipe_Thread_Info
657 {
658    RGBA_Image *im;
659    int         x, y, w, h;
660 };
661 #endif
662
663 struct _RGBA_Image
664 {
665    Image_Entry          cache_entry;
666
667    RGBA_Image_Flags     flags;
668    struct
669      {
670 /*      void           *module; */
671 /*      void           *loader; */
672 /*      char           *real_file; */
673         char           *comment;
674 //      int             format;
675      } info;
676
677    void                *extended_info;
678 #ifdef BUILD_PIPE_RENDER
679    RGBA_Pipe           *pipe;
680 #endif
681    int                  ref;
682
683 /*    unsigned char        scale; */
684
685    /* Colorspace stuff. */
686    struct {
687       void              *data;
688       Eina_Bool          no_free : 1;
689       Eina_Bool          dirty : 1;
690    } cs;
691
692    /* RGBA stuff */
693    struct {
694       DATA32            *data;
695       Eina_Bool          no_free : 1;
696    } image;
697
698    struct {
699       LK(lock);
700       Eina_List *list;
701       unsigned long long orig_usage;
702       unsigned long long usage_count;
703       int populate_count;
704       unsigned long long newest_usage;
705       unsigned long long newest_usage_count;
706    } cache;
707 };
708
709 struct _RGBA_Gradient_Color_Stop
710 {
711    EINA_INLIST;
712    int               r, g, b, a;
713    int               dist;
714 };
715
716 struct _RGBA_Gradient_Alpha_Stop
717 {
718    EINA_INLIST;
719    int               a;
720    int               dist;
721 };
722
723 struct _RGBA_Gradient
724 {
725    struct
726      {
727         DATA32        *data;
728         int            len;
729         float          angle;
730         int            direction;
731         float          offset;
732         Eina_Bool      has_alpha : 1;
733      } map;
734
735    struct {
736         Eina_Inlist *stops;
737         DATA32           *data;
738         int               nstops;
739         int               len;
740    }  color;
741    struct {
742         Eina_Inlist *stops;
743         DATA8            *data;
744         int               nstops;
745         int               len;
746    }  alpha;
747
748    struct
749      {
750         int            x, y, w, h;
751         int            spread;
752         float          angle;
753      } fill;
754    struct
755      {
756         char          *name;
757         char          *params;
758         RGBA_Gradient_Type *geometer;
759         void          *gdata;
760      } type;
761
762    int references;
763
764    Eina_Bool imported_data : 1;
765    Eina_Bool has_alpha : 1;
766 };
767
768 struct _RGBA_Gradient_Type
769 {
770    const char              *name;
771    void                    (*init)(void);
772    void                    (*shutdown)(void);
773    void                    (*geom_init)(RGBA_Gradient *gr);
774    void                    (*geom_set)(RGBA_Gradient *gr);
775    void                    (*geom_free)(void *gdata);
776    int                     (*has_alpha)(RGBA_Gradient *gr, int render_op);
777    int                     (*has_mask)(RGBA_Gradient *gr, int render_op);
778    int                     (*get_map_len)(RGBA_Gradient *gr);
779    Gfx_Func_Gradient_Fill  (*get_fill_func)(RGBA_Gradient *gr, int render_op, unsigned char aa);
780 };
781
782 struct _RGBA_Gradient2_Color_Np_Stop
783 {
784    EINA_INLIST;
785    int               r, g, b, a;
786    float             pos;
787    int               dist;
788 };
789
790 struct _RGBA_Gradient2
791 {
792    struct
793      {
794         DATA32        *data;
795         int            len;
796         Eina_Bool      has_alpha : 1;
797      } map;
798
799    struct {
800         Eina_Inlist *stops;
801         int               nstops;
802         DATA32           *cdata;
803         DATA8            *adata;
804         int               len;
805    }  stops;
806
807    struct
808      {
809         Evas_Common_Transform  transform;
810         int                    spread;
811      } fill;
812    struct
813      {
814         int                 id;
815         RGBA_Gradient2_Type *geometer;
816         void                *gdata;
817      } type;
818
819    int references;
820
821    Eina_Bool has_alpha : 1;
822 };
823
824 struct _RGBA_Gradient2_Type
825 {
826    const char              *name;
827    void                    (*init)(void);
828    void                    (*shutdown)(void);
829    void                    (*geom_init)(RGBA_Gradient2 *gr);
830    void                    (*geom_update)(RGBA_Gradient2 *gr);
831    void                    (*geom_free)(void *gdata);
832    int                     (*has_alpha)(RGBA_Gradient2 *gr, int render_op);
833    int                     (*has_mask)(RGBA_Gradient2 *gr, int render_op);
834    int                     (*get_map_len)(RGBA_Gradient2 *gr);
835    Gfx_Func_Gradient2_Fill  (*get_fill_func)(RGBA_Gradient2 *gr, int render_op);
836 };
837
838
839 struct _RGBA_Polygon_Point
840 {
841    EINA_INLIST;
842    int               x, y;
843 };
844
845 struct _RGBA_Font
846 {
847    Eina_List *fonts;
848    Font_Hint_Flags hinting;
849    int references;
850    LK(lock);
851 };
852
853 struct _RGBA_Font_Int
854 {
855    RGBA_Font_Source *src;
856
857    int               size;
858    int               real_size;
859    int               max_h;
860
861    struct {
862       FT_Size       size;
863    } ft;
864
865    Eina_Hash       *glyphs;
866
867    LK(ft_mutex);
868
869    Eina_Hash       *kerning;
870    Eina_Hash       *indexes;
871
872    int              usage;
873    Font_Hint_Flags hinting;
874
875    int              references;
876
877 };
878
879 struct _RGBA_Font_Source
880 {
881    const char       *name;
882    const char       *file;
883
884    void             *data;
885    int               data_size;
886    int               current_size;
887 #if 0 /* FIXME: charmap user is disabled and use a deprecated data type. */
888    Evas_Array_Hash  *charmap;
889 #endif
890
891    struct {
892       int           orig_upem;
893       FT_Face       face;
894    } ft;
895
896    int              references;
897 };
898
899 struct _RGBA_Font_Glyph
900 {
901    FT_UInt         index;
902    FT_Glyph        glyph;
903    FT_BitmapGlyph  glyph_out;
904    /* this is a problem - only 1 engine at a time can extend such a font... grrr */
905    void           *ext_dat;
906    void           (*ext_dat_free) (void *ext_dat);
907    RGBA_Font_Int   *fi;
908 };
909
910 struct _RGBA_Gfx_Compositor
911 {
912    const char *name;
913
914    void              (*init)(void);
915    void              (*shutdown)(void);
916
917    RGBA_Gfx_Func  (*composite_pixel_span_get)(RGBA_Image *src, RGBA_Image *dst, int pixels);
918    RGBA_Gfx_Func  (*composite_color_span_get)(DATA32 col, RGBA_Image *dst, int pixels);
919    RGBA_Gfx_Func  (*composite_pixel_color_span_get)(RGBA_Image *src, DATA32 col, RGBA_Image *dst, int pixels);
920    RGBA_Gfx_Func  (*composite_mask_color_span_get)(DATA32 col, RGBA_Image *dst, int pixels);
921    RGBA_Gfx_Func  (*composite_pixel_mask_span_get)(RGBA_Image *src, RGBA_Image *dst, int pixels);
922
923    RGBA_Gfx_Pt_Func  (*composite_pixel_pt_get)(Image_Entry_Flags src_flags, RGBA_Image *dst);
924    RGBA_Gfx_Pt_Func  (*composite_color_pt_get)(DATA32 col, RGBA_Image *dst);
925    RGBA_Gfx_Pt_Func  (*composite_pixel_color_pt_get)(Image_Entry_Flags src_flags, DATA32 col, RGBA_Image *dst);
926    RGBA_Gfx_Pt_Func  (*composite_mask_color_pt_get)(DATA32 col, RGBA_Image *dst);
927    RGBA_Gfx_Pt_Func  (*composite_pixel_mask_pt_get)(Image_Entry_Flags src_flags, RGBA_Image *dst);
928 };
929
930 #define EVAS_RECT_SPLIT 1
931 #ifdef EVAS_RECT_SPLIT
932 typedef struct list_node list_node_t;
933 typedef struct list list_t;
934 typedef struct rect rect_t;
935 typedef struct rect_node rect_node_t;
936
937 struct list_node
938 {
939     struct list_node *next;
940 };
941
942 struct list
943 {
944     struct list_node *head;
945     struct list_node *tail;
946 };
947
948 struct rect
949 {
950     short left;
951     short top;
952     short right;
953     short bottom;
954     short width;
955     short height;
956     int area;
957 };
958
959 struct rect_node
960 {
961     struct list_node _lst;
962     struct rect rect;
963 };
964
965 void rect_list_node_pool_set_max(int max);
966 void rect_list_node_pool_flush(void);
967 list_node_t *rect_list_node_pool_get(void);
968 void rect_list_node_pool_put(list_node_t *node);
969
970 void rect_init(rect_t *r, int x, int y, int w, int h);
971 void rect_list_append_node(list_t *rects, list_node_t *node);
972 void rect_list_append(list_t *rects, const rect_t r);
973 void rect_list_append_xywh(list_t *rects, int x, int y, int w, int h);
974 void rect_list_concat(list_t *rects, list_t *other);
975 list_node_t *rect_list_unlink_next(list_t *rects, list_node_t *parent_node);
976 void rect_list_del_next(list_t *rects, list_node_t *parent_node);
977 void rect_list_clear(list_t *rects);
978 void rect_list_del_split_strict(list_t *rects, const rect_t del_r);
979 void rect_list_add_split_strict(list_t *rects, list_node_t *node);
980 list_node_t *rect_list_add_split_fuzzy(list_t *rects, list_node_t *node, int accepted_error);
981 void rect_list_merge_rects(list_t *rects, list_t *to_merge, int accepted_error);void rect_list_add_split_fuzzy_and_merge(list_t *rects, list_node_t *node, int split_accepted_error, int merge_accepted_error);
982
983 void rect_print(const rect_t r);
984 void rect_list_print(const list_t rects);
985 #endif /* EVAS_RECT_SPLIT */
986
987 struct _Tilebuf
988 {
989    int outbuf_w;
990    int outbuf_h;
991
992    struct {
993       int           w, h;
994    } tile_size;
995
996 #ifdef RECTUPDATE
997    Regionbuf *rb;
998 #elif defined(EVAS_RECT_SPLIT)
999    int need_merge;
1000    list_t rects;
1001 #else
1002    struct {
1003       int           w, h;
1004       Tilebuf_Tile *tiles;
1005    } tiles;
1006 #endif
1007 };
1008
1009 struct _Tilebuf_Tile
1010 {
1011    Eina_Bool redraw : 1;
1012 /* FIXME: need these flags later - but not now */
1013 /*
1014    Eina_Bool done   : 1;
1015    Eina_Bool edge   : 1;
1016    Eina_Bool from   : 1;
1017
1018    struct {
1019       int dx, dy;
1020    } vector;
1021  */
1022 };
1023
1024 struct _Tilebuf_Rect
1025 {
1026    EINA_INLIST;
1027    int               x, y, w, h;
1028 };
1029 /*
1030 struct _Regionbuf
1031 {
1032    int w, h;
1033    Regionspan **spans;
1034 };
1035
1036 struct _Regionspan
1037 {
1038   EINA_INLIST;
1039    int x1, x2;
1040 };
1041 */
1042
1043 struct _Convert_Pal
1044 {
1045    int               references;
1046    int               count;
1047    Convert_Pal_Mode  colors;
1048    DATA8            *lookup;
1049    void             *data;
1050 };
1051
1052 /****/
1053
1054 /*****************************************************************************/
1055 #include "evas_macros.h"
1056
1057 #ifndef WORDS_BIGENDIAN
1058 /* x86 */
1059 #define A_VAL(p) ((DATA8 *)(p))[3]
1060 #define R_VAL(p) ((DATA8 *)(p))[2]
1061 #define G_VAL(p) ((DATA8 *)(p))[1]
1062 #define B_VAL(p) ((DATA8 *)(p))[0]
1063 #define AR_VAL(p) ((DATA16 *)(p)[1])
1064 #define GB_VAL(p) ((DATA16 *)(p)[0])
1065 #else
1066 /* ppc */
1067 #define A_VAL(p) ((DATA8 *)(p))[0]
1068 #define R_VAL(p) ((DATA8 *)(p))[1]
1069 #define G_VAL(p) ((DATA8 *)(p))[2]
1070 #define B_VAL(p) ((DATA8 *)(p))[3]
1071 #define AR_VAL(p) ((DATA16 *)(p)[0])
1072 #define GB_VAL(p) ((DATA16 *)(p)[1])
1073 #endif
1074
1075 #define RGB_JOIN(r,g,b) \
1076         (((r) << 16) + ((g) << 8) + (b))
1077
1078 #define ARGB_JOIN(a,r,g,b) \
1079         (((a) << 24) + ((r) << 16) + ((g) << 8) + (b))
1080
1081 #include "evas_blend_ops.h"
1082
1083 #define _EVAS_RENDER_FILL        -1
1084 #define _EVAS_RENDER_BLEND        0
1085 #define _EVAS_RENDER_BLEND_REL    1
1086 #define _EVAS_RENDER_COPY         2
1087 #define _EVAS_RENDER_COPY_REL     3
1088 #define _EVAS_RENDER_ADD          4
1089 #define _EVAS_RENDER_ADD_REL      5
1090 #define _EVAS_RENDER_SUB          6
1091 #define _EVAS_RENDER_SUB_REL      7
1092 #define _EVAS_RENDER_TINT         8
1093 #define _EVAS_RENDER_TINT_REL     9
1094 #define _EVAS_RENDER_MASK         10
1095 #define _EVAS_RENDER_MUL          11
1096 #define _EVAS_RENDER_CLIP         12
1097
1098 #define _EVAS_TEXTURE_REFLECT           0
1099 #define _EVAS_TEXTURE_REPEAT            1
1100 #define _EVAS_TEXTURE_RESTRICT          2
1101 #define _EVAS_TEXTURE_RESTRICT_REFLECT  3
1102 #define _EVAS_TEXTURE_RESTRICT_REPEAT   4
1103 #define _EVAS_TEXTURE_PAD               5
1104
1105 #define _EVAS_COLOR_SPACE_ARGB    0
1106 #define _EVAS_COLOR_SPACE_AHSV    1
1107
1108 /*****************************************************************************/
1109
1110 #ifdef __cplusplus
1111 extern "C" {
1112 #endif
1113
1114 /****/
1115 void evas_common_init                                   (void);
1116 void evas_common_shutdown                               (void);
1117
1118 EAPI void evas_common_cpu_init                          (void);
1119
1120 int  evas_common_cpu_have_cpuid                         (void);
1121 int  evas_common_cpu_has_feature                        (unsigned int feature);
1122 EAPI void evas_common_cpu_can_do                        (int *mmx, int *sse, int *sse2);
1123 EAPI void evas_common_cpu_end_opt                       (void);
1124
1125 /****/
1126 #include "../engines/common/evas_blend.h"
1127
1128 EAPI Gfx_Func_Copy        evas_common_draw_func_copy_get        (int pixels, int reverse);
1129
1130 /****/
1131 #include "../engines/common/evas_convert_color.h"
1132 #include "../engines/common/evas_convert_colorspace.h"
1133 #include "../engines/common/evas_convert_main.h"
1134 #include "../engines/common/evas_convert_yuv.h"
1135 #include "../engines/common/evas_scale_main.h"
1136 #include "../engines/common/evas_scale_smooth.h"
1137 #include "../engines/common/evas_scale_span.h"
1138
1139 /****/
1140 #include "../engines/common/evas_image.h"
1141
1142 /****/
1143 #include "../engines/common/evas_line.h"
1144 #include "../engines/common/evas_polygon.h"
1145 #include "../engines/common/evas_rectangle.h"
1146
1147 /****/
1148 EAPI void     evas_common_blit_init               (void);
1149
1150 EAPI void     evas_common_blit_rectangle          (const RGBA_Image *src, RGBA_Image *dst, int src_x, int src_y, int w, int h, int dst_x, int dst_y);
1151
1152 /****/
1153 #include "../engines/common/evas_gradient.h"
1154 #include "../engines/common/evas_font.h"
1155
1156 /****/
1157 EAPI void          evas_common_tilebuf_init               (void);
1158
1159 EAPI Tilebuf      *evas_common_tilebuf_new               (int w, int h);
1160 EAPI void          evas_common_tilebuf_free              (Tilebuf *tb);
1161 EAPI void          evas_common_tilebuf_set_tile_size     (Tilebuf *tb, int tw, int th);
1162 EAPI void          evas_common_tilebuf_get_tile_size     (Tilebuf *tb, int *tw, int *th);
1163 EAPI int           evas_common_tilebuf_add_redraw        (Tilebuf *tb, int x, int y, int w, int h);
1164 EAPI int           evas_common_tilebuf_del_redraw        (Tilebuf *tb, int x, int y, int w, int h);
1165 EAPI int           evas_common_tilebuf_add_motion_vector (Tilebuf *tb, int x, int y, int w, int h, int dx, int dy, int alpha);
1166 EAPI void          evas_common_tilebuf_clear             (Tilebuf *tb);
1167 EAPI Tilebuf_Rect *evas_common_tilebuf_get_render_rects  (Tilebuf *tb);
1168 EAPI void          evas_common_tilebuf_free_render_rects (Tilebuf_Rect *rects);
1169
1170 /*
1171 Regionbuf    *evas_common_regionbuf_new       (int w, int h);
1172 void          evas_common_regionbuf_free      (Regionbuf *rb);
1173 void          evas_common_regionbuf_clear     (Regionbuf *rb);
1174 void          evas_common_regionbuf_span_add  (Regionbuf *rb, int x1, int x2, int y);
1175 void          evas_common_regionbuf_span_del  (Regionbuf *rb, int x1, int x2, int y);
1176 Tilebuf_Rect *evas_common_regionbuf_rects_get (Regionbuf *rb);
1177 */
1178
1179 /****/
1180 #include "../engines/common/evas_draw.h"
1181
1182 #include "../engines/common/evas_map_image.h"
1183
1184 /****/
1185 #ifdef BUILD_PIPE_RENDER
1186 # include "../engines/common/evas_pipe.h"
1187 #endif
1188
1189 void              evas_font_dir_cache_free(void);
1190
1191 /****/
1192
1193 /*****************************************************************************/
1194
1195 #if defined(__ARM_ARCH__) && (__ARM_ARCH__ >= 70)
1196 #ifdef BUILD_NEON
1197 # include <arm_neon.h>
1198 #endif
1199 #endif
1200
1201 #ifdef __cplusplus
1202 }
1203 #endif
1204 #endif