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