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