fix some nasty image cache issues i've found like double-frees, leaks
[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 typedef enum _Font_Rend_Flags
514 {
515    FONT_REND_REGULAR   = 0,
516    FONT_REND_ITALIC    = (1 << 0),
517    FONT_REND_BOLD      = (1 << 1),
518 } Font_Rend_Flags;
519
520 /*****************************************************************************/
521
522 typedef struct _Filtered_Image Filtered_Image;
523
524 struct _RGBA_Image_Loadopts
525 {
526    int                  scale_down_by; // if > 1 then use this
527    double               dpi; // if > 0.0 use this
528    unsigned int         w, h; // if > 0 use this
529    struct {
530       unsigned int      x, y, w, h;
531    } region;
532 };
533
534 struct _Image_Entry_Flags
535 {
536    Eina_Bool loaded       : 1;
537    Eina_Bool in_progress  : 1;
538    Eina_Bool dirty        : 1;
539    Eina_Bool activ        : 1;
540    
541    Eina_Bool need_data    : 1;
542    Eina_Bool lru_nodata   : 1;
543    Eina_Bool cached       : 1;
544    Eina_Bool alpha        : 1;
545    
546    Eina_Bool lru          : 1;
547    Eina_Bool alpha_sparse : 1;
548 #ifdef BUILD_ASYNC_PRELOAD
549    Eina_Bool preload_done : 1;
550    Eina_Bool delete_me    : 1;
551    Eina_Bool pending      : 1;
552 #endif
553 };
554
555 struct _Evas_Cache_Target
556 {
557   EINA_INLIST;
558   const void *target;
559   void *data;
560 };
561
562 struct _Image_Timestamp
563 {
564    time_t mtime;
565    off_t  size;
566    ino_t  ino;
567 #ifdef _STAT_VER_LINUX
568    unsigned long int mtime_nsec;
569 #endif   
570 };
571
572 struct _Image_Entry
573 {
574    EINA_INLIST;
575
576    Evas_Cache_Image      *cache;
577
578    const char            *cache_key;
579
580    const char            *file;
581    const char            *key;
582
583    Evas_Cache_Target     *targets;
584    Evas_Preload_Pthread  *preload;
585
586    Image_Timestamp        tstamp;
587
588    int                    references;
589 #ifdef EVAS_FRAME_QUEUING
590    LK(lock_references);   // needed for accessing references
591 #endif
592
593 #ifdef BUILD_PIPE_RENDER
594    RGBA_Pipe           *pipe;
595 #ifdef EVAS_FRAME_QUEUING
596    LK(ref_fq_add);
597    LK(ref_fq_del);
598    pthread_cond_t cond_fq_del;
599    int ref_fq[2];               // ref_fq[0] is for addition, ref_fq[1] is for deletion
600 #endif
601 #endif
602
603    unsigned char          scale;
604
605    RGBA_Image_Loadopts    load_opts;
606    int                    space;
607    unsigned int           w;
608    unsigned int           h;
609
610    struct
611      {
612         unsigned int w;
613         unsigned int h;
614      } allocated;
615
616    struct
617      {
618         void            *module;
619         void            *loader;
620      } info;
621
622 #ifdef BUILD_ASYNC_PRELOAD
623    LK(lock);
624    LK(lock_cancel);
625    Eina_Bool unload_cancel : 1;
626 #endif
627
628    Image_Entry_Flags      flags;
629    Evas_Image_Scale_Hint  scale_hint;
630    void                  *data1, *data2;
631    int                    server_id;
632    int                    connect_num;
633    int                    channel;
634 };
635
636 struct _Engine_Image_Entry
637 {
638    EINA_INLIST;
639
640    /* Upper Engine data. */
641    Image_Entry                  *src;
642
643    /* Cache stuff. */
644    Evas_Cache_Engine_Image      *cache;
645    const char                   *cache_key;
646
647    struct
648    {
649      Eina_Bool                   cached : 1;
650      Eina_Bool                   activ : 1;
651      Eina_Bool                   dirty : 1;
652      Eina_Bool                   loaded : 1;
653      Eina_Bool                   need_parent : 1;
654    } flags;
655
656    int                           references;
657    int                           w;
658    int                           h;
659 };
660
661 struct _Cutout_Rect
662 {
663    int               x, y, w, h;
664 };
665
666 struct _Cutout_Rects
667 {
668    Cutout_Rect*      rects;
669    int               active;
670    int               max;
671 };
672
673 struct _Evas_Common_Transform
674 {
675    float  mxx, mxy, mxz;
676    float  myx, myy, myz;
677    float  mzx, mzy, mzz;
678 };
679
680 struct _RGBA_Draw_Context
681 {
682    struct {
683       Eina_Bool use : 1;
684       DATA32 col;
685    } mul;
686    struct {
687       DATA32 col;
688    } col;
689    struct RGBA_Draw_Context_clip {
690       int    x, y, w, h;
691       Eina_Bool use : 1;
692    } clip;
693    struct {
694       int x, y, w, h;
695       RGBA_Image *mask;
696    } mask;
697    Cutout_Rects cutout;
698    struct {
699       struct {
700          void *(*gl_new)  (void *data, RGBA_Font_Glyph *fg);
701          void  (*gl_free) (void *ext_dat);
702          void  (*gl_draw) (void *data, void *dest, void *context, RGBA_Font_Glyph *fg, int x, int y);
703       } func;
704       void *data;
705    } font_ext;
706    struct {
707       int color_space;
708    } interpolation;
709    struct {
710       int y, h;
711    } sli;
712    int            render_op;
713    Eina_Bool anti_alias : 1;
714 };
715
716 #ifdef BUILD_PIPE_RENDER
717 #include "../engines/common/evas_map_image.h"
718 #include "../engines/common/evas_text_utils.h"
719
720 struct _RGBA_Pipe_Op
721 {
722    RGBA_Draw_Context         context;
723    void                    (*op_func) (RGBA_Image *dst, RGBA_Pipe_Op *op, RGBA_Pipe_Thread_Info *info);
724    void                    (*free_func) (RGBA_Pipe_Op *op);
725
726    union {
727       struct {
728          int                 x, y, w, h;
729       } rect;
730       struct {
731          int                 x0, y0, x1, y1;
732       } line;
733       struct {
734          RGBA_Polygon_Point *points;
735       } poly;
736       struct {
737          RGBA_Font          *font;
738          int                 x, y;
739          Eina_Unicode       *text;
740          Evas_Text_Props     intl_props;
741       } text;
742       struct {
743          RGBA_Image         *src;
744          int                 sx, sy, sw, sh, dx, dy, dw, dh;
745          int                 smooth;
746          char               *text;
747       } image;
748       struct {
749          RGBA_Image         *src;
750          RGBA_Map_Point     *p;
751          int                 npoints;
752          int                 smooth;
753          int                 level;
754       } map;
755    } op;
756 };
757
758 #define PIPE_LEN 256
759
760 struct _RGBA_Pipe
761 {
762    EINA_INLIST;
763    int               op_num;
764    RGBA_Pipe_Op      op[PIPE_LEN];
765 };
766
767 struct _RGBA_Pipe_Thread_Info
768 {
769    RGBA_Image *im;
770    int         x, y, w, h;
771 };
772 #endif
773
774 struct _RGBA_Image
775 {
776    Image_Entry          cache_entry;
777
778    RGBA_Image_Flags     flags;
779    struct
780      {
781 /*      void           *module; */
782 /*      void           *loader; */
783 /*      char           *real_file; */
784         char           *comment;
785 //      int             format;
786      } info;
787
788    void                *extended_info;
789    int                  ref;
790
791 /*    unsigned char        scale; */
792
793    /* Colorspace stuff. */
794    struct {
795       void              *data;
796       Eina_Bool          no_free : 1;
797       Eina_Bool          dirty : 1;
798    } cs;
799
800    /* RGBA stuff */
801    struct {
802       DATA32            *data;
803       Eina_Bool          no_free : 1;
804    } image;
805
806    struct {
807       DATA8             *mask;
808       Eina_Bool          dirty: 1;
809    } mask;
810
811    Eina_List            *filtered;
812
813    struct {
814       LK(lock);
815       Eina_List *list;
816       unsigned long long orig_usage;
817       unsigned long long usage_count;
818       int populate_count;
819       unsigned long long newest_usage;
820       unsigned long long newest_usage_count;
821    } cache;
822 };
823
824 struct _RGBA_Polygon_Point
825 {
826    EINA_INLIST;
827    int               x, y;
828 };
829
830 struct _RGBA_Map_Point
831 {
832    FPc x, y; // x, y screenspace
833    float fx, fy, fz; // x, y, z in floats
834 //   FPc x3, y3; // x, y 3d space
835    FPc z; // z in world space. optional
836    FPc u, v; // u, v in tex coords
837    DATA32 col; // color at this point
838    // for perspective correctness - only point 0 has relevant info
839    FPc px, py, z0, foc;
840 };
841
842 struct _Filtered_Image
843 {
844    void       *key;
845    size_t      keylen;
846    RGBA_Image *image;
847    int ref;
848 };
849
850 // for fonts...
851 /////
852 typedef struct _Fash_Item_Index_Map Fash_Item_Index_Map;
853 typedef struct _Fash_Int_Map        Fash_Int_Map;
854 typedef struct _Fash_Int_Map2       Fash_Int_Map2;
855 typedef struct _Fash_Int            Fash_Int;
856 struct _Fash_Item_Index_Map
857 {
858    RGBA_Font_Int *fint;
859    int            index;
860 };
861 struct _Fash_Int_Map
862 {
863   Fash_Item_Index_Map item[256];
864 };
865 struct _Fash_Int_Map2
866 {
867    Fash_Int_Map *bucket[256];
868 };
869 struct _Fash_Int
870 {
871    Fash_Int_Map2 *bucket[256];
872    void (*freeme) (Fash_Int *fash);
873 };
874
875 /////
876 typedef struct _Fash_Glyph_Map  Fash_Glyph_Map;
877 typedef struct _Fash_Glyph_Map2 Fash_Glyph_Map2;
878 typedef struct _Fash_Glyph      Fash_Glyph;
879 struct _Fash_Glyph_Map
880 {
881    RGBA_Font_Glyph *item[256];
882 };
883 struct _Fash_Glyph_Map2
884 {
885    Fash_Glyph_Map *bucket[256];
886 };
887 struct _Fash_Glyph
888 {
889    Fash_Glyph_Map2 *bucket[256];
890    void (*freeme) (Fash_Glyph *fash);
891 };
892 /////
893
894 struct _RGBA_Font
895 {
896    Eina_List       *fonts;
897    Fash_Int        *fash;
898    Font_Hint_Flags  hinting;
899    int              references;
900 #ifdef EVAS_FRAME_QUEUING
901    int              ref_fq[2]; //ref_fq[0] is for addition, ref_fq[1] is for deletion
902    pthread_cond_t   cond_fq_del;
903    LK(ref_fq_add);
904    LK(ref_fq_del);
905 #endif
906    LK(lock);
907    unsigned char    sizeok : 1;
908 };
909
910 struct _RGBA_Font_Int
911 {
912    EINA_INLIST;
913    RGBA_Font_Source *src;
914    Eina_Hash        *kerning;
915    Fash_Glyph       *fash;
916    unsigned int      size;
917    int               real_size;
918    int               max_h;
919    int               references;
920    int               usage;
921    struct {
922       FT_Size       size;
923    } ft;
924    LK(ft_mutex);
925    Font_Hint_Flags  hinting;
926    Font_Rend_Flags  wanted_rend; /* The wanted rendering style */
927    Font_Rend_Flags  runtime_rend; /* The rendering we need to do on runtime
928                                      in order to comply with the wanted_rend. */
929    unsigned char    sizeok : 1;
930    unsigned char    inuse : 1;
931 };
932
933 #include "../engines/common/evas_font_ot.h"
934
935 struct _RGBA_Font_Source
936 {
937    const char       *name;
938    const char       *file;
939    void             *data;
940    unsigned int      current_size;
941    int               data_size;
942    int               references;
943    struct {
944       int            orig_upem;
945       FT_Face        face;
946    } ft;
947 #ifdef OT_SUPPORT
948    struct {
949       void *face;
950    } hb;
951 #endif
952 };
953
954 struct _RGBA_Font_Glyph
955 {
956    FT_UInt         index;
957    FT_Glyph        glyph;
958    FT_BitmapGlyph  glyph_out;
959    /* this is a problem - only 1 engine at a time can extend such a font... grrr */
960    void           *ext_dat;
961    void           (*ext_dat_free) (void *ext_dat);
962    RGBA_Font_Int   *fi;
963 };
964
965 struct _RGBA_Gfx_Compositor
966 {
967    const char *name;
968
969    void              (*init)(void);
970    void              (*shutdown)(void);
971
972    RGBA_Gfx_Func  (*composite_pixel_span_get)(RGBA_Image *src, RGBA_Image *dst, int pixels);
973    RGBA_Gfx_Func  (*composite_color_span_get)(DATA32 col, RGBA_Image *dst, int pixels);
974    RGBA_Gfx_Func  (*composite_pixel_color_span_get)(RGBA_Image *src, DATA32 col, RGBA_Image *dst, int pixels);
975    RGBA_Gfx_Func  (*composite_mask_color_span_get)(DATA32 col, RGBA_Image *dst, int pixels);
976    RGBA_Gfx_Func  (*composite_pixel_mask_span_get)(RGBA_Image *src, RGBA_Image *dst, int pixels);
977
978    RGBA_Gfx_Pt_Func  (*composite_pixel_pt_get)(Image_Entry_Flags src_flags, RGBA_Image *dst);
979    RGBA_Gfx_Pt_Func  (*composite_color_pt_get)(DATA32 col, RGBA_Image *dst);
980    RGBA_Gfx_Pt_Func  (*composite_pixel_color_pt_get)(Image_Entry_Flags src_flags, DATA32 col, RGBA_Image *dst);
981    RGBA_Gfx_Pt_Func  (*composite_mask_color_pt_get)(DATA32 col, RGBA_Image *dst);
982    RGBA_Gfx_Pt_Func  (*composite_pixel_mask_pt_get)(Image_Entry_Flags src_flags, RGBA_Image *dst);
983 };
984
985 #define EVAS_RECT_SPLIT 1
986 #ifdef EVAS_RECT_SPLIT
987 typedef struct list_node list_node_t;
988 typedef struct list list_t;
989 typedef struct rect rect_t;
990 typedef struct rect_node rect_node_t;
991
992 struct list_node
993 {
994     struct list_node *next;
995 };
996
997 struct list
998 {
999     struct list_node *head;
1000     struct list_node *tail;
1001 };
1002
1003 struct rect
1004 {
1005     short left;
1006     short top;
1007     short right;
1008     short bottom;
1009     short width;
1010     short height;
1011     int area;
1012 };
1013
1014 struct rect_node
1015 {
1016     struct list_node _lst;
1017     struct rect rect;
1018 };
1019
1020 void rect_list_node_pool_set_max(int max);
1021 void rect_list_node_pool_flush(void);
1022 list_node_t *rect_list_node_pool_get(void);
1023 void rect_list_node_pool_put(list_node_t *node);
1024
1025 void rect_init(rect_t *r, int x, int y, int w, int h);
1026 void rect_list_append_node(list_t *rects, list_node_t *node);
1027 void rect_list_append(list_t *rects, const rect_t r);
1028 void rect_list_append_xywh(list_t *rects, int x, int y, int w, int h);
1029 void rect_list_concat(list_t *rects, list_t *other);
1030 list_node_t *rect_list_unlink_next(list_t *rects, list_node_t *parent_node);
1031 void rect_list_del_next(list_t *rects, list_node_t *parent_node);
1032 void rect_list_clear(list_t *rects);
1033 void rect_list_del_split_strict(list_t *rects, const rect_t del_r);
1034 void rect_list_add_split_strict(list_t *rects, list_node_t *node);
1035 list_node_t *rect_list_add_split_fuzzy(list_t *rects, list_node_t *node, int accepted_error);
1036 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);
1037
1038 void rect_print(const rect_t r);
1039 void rect_list_print(const list_t rects);
1040 #endif /* EVAS_RECT_SPLIT */
1041
1042 struct _Tilebuf
1043 {
1044    int outbuf_w;
1045    int outbuf_h;
1046
1047    struct {
1048       int           w, h;
1049    } tile_size;
1050
1051 #ifdef RECTUPDATE
1052    Regionbuf *rb;
1053 #elif defined(EVAS_RECT_SPLIT)
1054    int need_merge;
1055    list_t rects;
1056 #else
1057    struct {
1058       int           w, h;
1059       Tilebuf_Tile *tiles;
1060    } tiles;
1061 #endif
1062 };
1063
1064 struct _Tilebuf_Tile
1065 {
1066    Eina_Bool redraw : 1;
1067 /* FIXME: need these flags later - but not now */
1068 /*
1069    Eina_Bool done   : 1;
1070    Eina_Bool edge   : 1;
1071    Eina_Bool from   : 1;
1072
1073    struct {
1074       int dx, dy;
1075    } vector;
1076  */
1077 };
1078
1079 struct _Tilebuf_Rect
1080 {
1081    EINA_INLIST;
1082    int               x, y, w, h;
1083 };
1084 /*
1085 struct _Regionbuf
1086 {
1087    int w, h;
1088    Regionspan **spans;
1089 };
1090
1091 struct _Regionspan
1092 {
1093   EINA_INLIST;
1094    int x1, x2;
1095 };
1096 */
1097
1098 struct _Convert_Pal
1099 {
1100    int               references;
1101    int               count;
1102    Convert_Pal_Mode  colors;
1103    DATA8            *lookup;
1104    void             *data;
1105 };
1106
1107 /****/
1108
1109 /*****************************************************************************/
1110 #include "evas_macros.h"
1111
1112 #ifndef WORDS_BIGENDIAN
1113 /* x86 */
1114 #define A_VAL(p) (((DATA8 *)(p))[3])
1115 #define R_VAL(p) (((DATA8 *)(p))[2])
1116 #define G_VAL(p) (((DATA8 *)(p))[1])
1117 #define B_VAL(p) (((DATA8 *)(p))[0])
1118 #define AR_VAL(p) ((DATA16 *)(p)[1])
1119 #define GB_VAL(p) ((DATA16 *)(p)[0])
1120 #else
1121 /* ppc */
1122 #define A_VAL(p) (((DATA8 *)(p))[0])
1123 #define R_VAL(p) (((DATA8 *)(p))[1])
1124 #define G_VAL(p) (((DATA8 *)(p))[2])
1125 #define B_VAL(p) (((DATA8 *)(p))[3])
1126 #define AR_VAL(p) ((DATA16 *)(p)[0])
1127 #define GB_VAL(p) ((DATA16 *)(p)[1])
1128 #endif
1129
1130 #define RGB_JOIN(r,g,b) \
1131         (((r) << 16) + ((g) << 8) + (b))
1132
1133 #define ARGB_JOIN(a,r,g,b) \
1134         (((a) << 24) + ((r) << 16) + ((g) << 8) + (b))
1135
1136 #include "evas_blend_ops.h"
1137
1138 #define _EVAS_RENDER_FILL        -1
1139 #define _EVAS_RENDER_BLEND        0
1140 #define _EVAS_RENDER_BLEND_REL    1
1141 #define _EVAS_RENDER_COPY         2
1142 #define _EVAS_RENDER_COPY_REL     3
1143 #define _EVAS_RENDER_ADD          4
1144 #define _EVAS_RENDER_ADD_REL      5
1145 #define _EVAS_RENDER_SUB          6
1146 #define _EVAS_RENDER_SUB_REL      7
1147 #define _EVAS_RENDER_TINT         8
1148 #define _EVAS_RENDER_TINT_REL     9
1149 #define _EVAS_RENDER_MASK         10
1150 #define _EVAS_RENDER_MUL          11
1151 #define _EVAS_RENDER_CLIP         12
1152
1153 #define _EVAS_TEXTURE_REFLECT           0
1154 #define _EVAS_TEXTURE_REPEAT            1
1155 #define _EVAS_TEXTURE_RESTRICT          2
1156 #define _EVAS_TEXTURE_RESTRICT_REFLECT  3
1157 #define _EVAS_TEXTURE_RESTRICT_REPEAT   4
1158 #define _EVAS_TEXTURE_PAD               5
1159
1160 #define _EVAS_COLOR_SPACE_ARGB    0
1161 #define _EVAS_COLOR_SPACE_AHSV    1
1162
1163 /*****************************************************************************/
1164
1165 #ifdef __cplusplus
1166 extern "C" {
1167 #endif
1168
1169 /****/
1170 void evas_common_init                                   (void);
1171 void evas_common_shutdown                               (void);
1172
1173 EAPI void evas_common_cpu_init                          (void);
1174
1175 int  evas_common_cpu_have_cpuid                         (void);
1176 int  evas_common_cpu_has_feature                        (unsigned int feature);
1177 EAPI void evas_common_cpu_can_do                        (int *mmx, int *sse, int *sse2);
1178 EAPI void evas_common_cpu_end_opt                       (void);
1179
1180 /****/
1181 #include "../engines/common/evas_blend.h"
1182
1183 EAPI Gfx_Func_Copy        evas_common_draw_func_copy_get        (int pixels, int reverse);
1184
1185 /****/
1186 #include "../engines/common/evas_convert_color.h"
1187 #include "../engines/common/evas_convert_colorspace.h"
1188 #include "../engines/common/evas_convert_main.h"
1189 #include "../engines/common/evas_convert_yuv.h"
1190 #include "../engines/common/evas_scale_main.h"
1191 #include "../engines/common/evas_scale_smooth.h"
1192 #include "../engines/common/evas_scale_span.h"
1193
1194 /****/
1195 #include "../engines/common/evas_image.h"
1196
1197 /****/
1198 #include "../engines/common/evas_line.h"
1199 #include "../engines/common/evas_polygon.h"
1200 #include "../engines/common/evas_rectangle.h"
1201
1202 /****/
1203 EAPI void     evas_common_blit_init               (void);
1204
1205 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);
1206
1207 /****/
1208 #include "../engines/common/evas_font.h"
1209
1210 /****/
1211 EAPI void          evas_common_tilebuf_init               (void);
1212
1213 EAPI Tilebuf      *evas_common_tilebuf_new               (int w, int h);
1214 EAPI void          evas_common_tilebuf_free              (Tilebuf *tb);
1215 EAPI void          evas_common_tilebuf_set_tile_size     (Tilebuf *tb, int tw, int th);
1216 EAPI void          evas_common_tilebuf_get_tile_size     (Tilebuf *tb, int *tw, int *th);
1217 EAPI int           evas_common_tilebuf_add_redraw        (Tilebuf *tb, int x, int y, int w, int h);
1218 EAPI int           evas_common_tilebuf_del_redraw        (Tilebuf *tb, int x, int y, int w, int h);
1219 EAPI int           evas_common_tilebuf_add_motion_vector (Tilebuf *tb, int x, int y, int w, int h, int dx, int dy, int alpha);
1220 EAPI void          evas_common_tilebuf_clear             (Tilebuf *tb);
1221 EAPI Tilebuf_Rect *evas_common_tilebuf_get_render_rects  (Tilebuf *tb);
1222 EAPI void          evas_common_tilebuf_free_render_rects (Tilebuf_Rect *rects);
1223
1224 /*
1225 Regionbuf    *evas_common_regionbuf_new       (int w, int h);
1226 void          evas_common_regionbuf_free      (Regionbuf *rb);
1227 void          evas_common_regionbuf_clear     (Regionbuf *rb);
1228 void          evas_common_regionbuf_span_add  (Regionbuf *rb, int x1, int x2, int y);
1229 void          evas_common_regionbuf_span_del  (Regionbuf *rb, int x1, int x2, int y);
1230 Tilebuf_Rect *evas_common_regionbuf_rects_get (Regionbuf *rb);
1231 */
1232
1233 /****/
1234 #include "../engines/common/evas_draw.h"
1235
1236 #include "../engines/common/evas_map_image.h"
1237
1238 /****/
1239 #ifdef BUILD_PIPE_RENDER
1240 # include "../engines/common/evas_pipe.h"
1241 #endif
1242
1243 void              evas_font_dir_cache_free(void);
1244
1245 /****/
1246
1247 /*****************************************************************************/
1248
1249 #ifdef __cplusplus
1250 }
1251 #endif
1252
1253 #endif