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