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