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