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