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 STDC_HEADERS
9 # include <stdlib.h>
10 # include <stddef.h>
11 #else
12 # ifdef HAVE_STDLIB_H
13 #  include <stdlib.h>
14 # endif
15 #endif
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <time.h>
23 #include <ctype.h>
24 #include <stdint.h>
25 #include <unistd.h>
26 
27 #ifdef HAVE_PIXMAN
28 #include <pixman.h>
29 #endif
30 
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <unistd.h>
34 
35 #include <Eina.h>
36 #include <Eo.h>
37 #include <Ector.h>
38 
39 #ifdef BUILD_LOADER_EET
40 # include <Eet.h>
41 #endif
42 
43 #ifndef EFL_CANVAS_OBJECT_PROTECTED
44 # define EFL_CANVAS_OBJECT_PROTECTED
45 #endif
46 
47 #include "Evas.h"
48 
49 #define EFL_INTERNAL_UNSTABLE
50 #include "Evas_Internal.h"
51 
52 #include "../common/evas_font.h"
53 
54 #ifdef EAPI
55 # undef EAPI
56 #endif
57 
58 #ifdef _WIN32
59 # ifdef EFL_BUILD
60 #  ifdef DLL_EXPORT
61 #   define EAPI __declspec(dllexport)
62 #  else
63 #   define EAPI
64 #  endif
65 # else
66 #  define EAPI __declspec(dllimport)
67 # endif
68 #else
69 # ifdef __GNUC__
70 #  if __GNUC__ >= 4
71 #   define EAPI __attribute__ ((visibility("default")))
72 #  else
73 #   define EAPI
74 #  endif
75 # else
76 #  define EAPI
77 # endif
78 #endif
79 
80 #ifndef HAVE_LROUND
81 /* right now i dont care about rendering bugs on platforms without lround
82  (e.g. windows/vc++... yay!)
83  FIXME: http://cgit.freedesktop.org/cairo/tree/src/cairo-misc.c#n487
84 */
85 #define lround(x) (((x) < 0) ? (long int)ceil((x) - 0.5) : (long int)floor((x) + 0.5))
86 #endif
87 
88 /* macros needed to log message through eina_log */
89 EAPI extern int _evas_log_dom_global;
90 #ifdef  _EVAS_DEFAULT_LOG_DOM
91 # undef _EVAS_DEFAULT_LOG_DOM
92 #endif
93 #define _EVAS_DEFAULT_LOG_DOM _evas_log_dom_global
94 
95 #ifdef EVAS_DEFAULT_LOG_COLOR
96 # undef EVAS_DEFAULT_LOG_COLOR
97 #endif
98 #define EVAS_DEFAULT_LOG_COLOR EINA_COLOR_BLUE
99 
100 #ifdef ERR
101 # undef ERR
102 #endif
103 #define ERR(...) EINA_LOG_DOM_ERR(_EVAS_DEFAULT_LOG_DOM, __VA_ARGS__)
104 
105 #ifdef DBG
106 # undef DBG
107 #endif
108 #define DBG(...) EINA_LOG_DOM_DBG(_EVAS_DEFAULT_LOG_DOM, __VA_ARGS__)
109 
110 #ifdef INF
111 # undef INF
112 #endif
113 #define INF(...) EINA_LOG_DOM_INFO(_EVAS_DEFAULT_LOG_DOM, __VA_ARGS__)
114 
115 #ifdef WRN
116 # undef WRN
117 #endif
118 #define WRN(...) EINA_LOG_DOM_WARN(_EVAS_DEFAULT_LOG_DOM, __VA_ARGS__)
119 
120 #ifdef CRI
121 # undef CRI
122 #endif
123 #define CRI(...) EINA_LOG_DOM_CRIT(_EVAS_DEFAULT_LOG_DOM, __VA_ARGS__)
124 
125 #include "evas_options.h"
126 
127 #if defined(__ARM_ARCH_3M__)
128 # define __ARM_ARCH__ 40
129 #endif
130 #if defined(__ARM_ARCH_4__)
131 # define __ARM_ARCH__ 40
132 #endif
133 #if defined(__ARM_ARCH_4T__)
134 # define __ARM_ARCH__ 41
135 #endif
136 
137 #if defined(__ARM_ARCH_5__)
138 # define __ARM_ARCH__ 50
139 #endif
140 #if defined(__ARM_ARCH_5T__)
141 # define __ARM_ARCH__ 51
142 #endif
143 #if defined(__ARM_ARCH_5E__)
144 # define __ARM_ARCH__ 52
145 #endif
146 #if defined(__ARM_ARCH_5TE__)
147 # define __ARM_ARCH__ 53
148 #endif
149 #if defined(__ARM_ARCH_5TEJ__)
150 # define __ARM_ARCH__ 54
151 #endif
152 
153 #if defined(__ARM_ARCH_6__)
154 # define __ARM_ARCH__ 60
155 #endif
156 #if defined(__ARM_ARCH_6J__)
157 # define __ARM_ARCH__ 61
158 #endif
159 #if defined(__ARM_ARCH_6K__)
160 # define __ARM_ARCH__ 62
161 #endif
162 #if defined(__ARM_ARCH_6Z__)
163 # define __ARM_ARCH__ 63
164 #endif
165 #if defined(__ARM_ARCH_6ZK__)
166 # define __ARM_ARCH__ 64
167 #endif
168 #if defined(__ARM_ARCH_6T2__)
169 # define __ARM_ARCH__ 65
170 #endif
171 
172 #if defined(__ARM_ARCH_7__)
173 # define __ARM_ARCH__ 70
174 #endif
175 #if defined(__ARM_ARCH_7A__)
176 # define __ARM_ARCH__ 71
177 #endif
178 #if defined(__ARM_ARCH_7R__)
179 # define __ARM_ARCH__ 72
180 #endif
181 #if defined(__ARM_ARCH_7M__)
182 # define __ARM_ARCH__ 73
183 #endif
184 
185 #define SLK(x) Eina_Spinlock x
186 #define SLKI(x) eina_spinlock_new(&(x))
187 #define SLKD(x) eina_spinlock_free(&(x))
188 #define SLKL(x) eina_spinlock_take(&(x))
189 #define SLKT(x) eina_spinlock_take_try(&(x))
190 #define SLKU(x) eina_spinlock_release(&(x))
191 
192 #define LK(x)  Eina_Lock x
193 #define LKI(x) eina_lock_new(&(x))
194 #define LKD(x) eina_lock_free(&(x))
195 #define LKL(x) eina_lock_take(&(x))
196 #define LKT(x) eina_lock_take_try(&(x))
197 #define LKU(x) eina_lock_release(&(x))
198 #define LKDBG(x) eina_lock_debug(&(x))
199 
200 /* for rwlocks */
201 #define RWLK(x) Eina_RWLock x
202 #define RWLKI(x) eina_rwlock_new(&(x))
203 #define RWLKD(x) eina_rwlock_free(&(x))
204 #define RDLKL(x) eina_rwlock_take_read(&(x))
205 #define WRLKL(x) eina_rwlock_take_write(&(x))
206 #define RWLKU(x) eina_rwlock_release(&(x))
207 
208 # define TH(x)  pthread_t x
209 # define THI(x) int x
210 # define TH_MAX 8
211 
212 #ifdef __GNUC__
213 # if __GNUC__ >= 4
214 // BROKEN in gcc 4 on amd64
215 //#  pragma GCC visibility push(hidden)
216 # endif
217 #define LIKELY(x)   __builtin_expect(!!(x), 1)
218 #define UNLIKELY(x) __builtin_expect(!!(x), 0)
219 #else
220 #define LIKELY(x)   (x)
221 #define UNLIKELY(x) (x)
222 #endif
223 
224 /*****************************************************************************/
225 
226 /* use exact rects for updates not tiles */
227 //#define NEWTILER
228 #define TILESIZE 8
229 #define IMG_MAX_SIZE 65000
230 
231 #define IMG_TOO_BIG(w, h) \
232    ((((unsigned long long)w) * ((unsigned long long)h)) >= \
233        ((1ULL << (29 * (sizeof(void *) / 4))) - 2048))
234 
235 /* not every converter supports no-dither or line-dither, then they will
236  * fallback to table version, in these cases default to small table.
237  */
238 #if defined(BUILD_NO_DITHER_MASK) || defined(BUILD_LINE_DITHER_MASK)
239 #ifndef BUILD_SMALL_DITHER_MASK
240 #define BUILD_SMALL_DITHER_MASK 1
241 #endif
242 #endif
243 
244 #ifdef BUILD_SMALL_DITHER_MASK
245 # define DM_TABLE     _evas_dither_44
246 # define DM_SIZE      4
247 # define DM_BITS      4
248 # define DM_DIV       16
249 # define USE_DITHER_44 1
250 #else
251 # define DM_TABLE     _evas_dither_128128
252 # define DM_SIZE      128
253 # define DM_BITS      6
254 # define DM_DIV       64
255 # define USE_DITHER_128128 1
256 #endif
257 
258 #define DM_MSK       (DM_SIZE - 1)
259 #define DM_SHF(_b)   (DM_BITS - (8 - _b))
260 /* Supports negative right shifts */
261 #define DM_SHR(x, _b)   ((DM_SHF(_b) >= 0) ? \
262       ((x) >> DM_SHF(_b)) : ((x) << -DM_SHF(_b)))
263 
264 /* if more than 1/ALPHA_SPARSE_INV_FRACTION is "alpha" (1-254) then sparse
265  * alpha flag gets set */
266 #define ALPHA_SPARSE_INV_FRACTION 3
267 
268 /*****************************************************************************/
269 
270 #if defined(__ARM_ARCH_3M__)
271 # define __ARM_ARCH__ 40
272 #endif
273 #if defined(__ARM_ARCH_4__)
274 # define __ARM_ARCH__ 40
275 #endif
276 #if defined(__ARM_ARCH_4T__)
277 # define __ARM_ARCH__ 41
278 #endif
279 
280 #if defined(__ARM_ARCH_5__)
281 # define __ARM_ARCH__ 50
282 #endif
283 #if defined(__ARM_ARCH_5T__)
284 # define __ARM_ARCH__ 51
285 #endif
286 #if defined(__ARM_ARCH_5E__)
287 # define __ARM_ARCH__ 52
288 #endif
289 #if defined(__ARM_ARCH_5TE__)
290 # define __ARM_ARCH__ 53
291 #endif
292 #if defined(__ARM_ARCH_5TEJ__)
293 # define __ARM_ARCH__ 54
294 #endif
295 
296 #if defined(__ARM_ARCH_6__)
297 # define __ARM_ARCH__ 60
298 #endif
299 #if defined(__ARM_ARCH_6J__)
300 # define __ARM_ARCH__ 61
301 #endif
302 #if defined(__ARM_ARCH_6K__)
303 # define __ARM_ARCH__ 62
304 #endif
305 #if defined(__ARM_ARCH_6Z__)
306 # define __ARM_ARCH__ 63
307 #endif
308 #if defined(__ARM_ARCH_6ZK__)
309 # define __ARM_ARCH__ 64
310 #endif
311 #if defined(__ARM_ARCH_6T2__)
312 # define __ARM_ARCH__ 65
313 #endif
314 
315 #if defined(__ARM_ARCH_7__)
316 # define __ARM_ARCH__ 70
317 #endif
318 #if defined(__ARM_ARCH_7A__)
319 # define __ARM_ARCH__ 71
320 #endif
321 #if defined(__ARM_ARCH_7R__)
322 # define __ARM_ARCH__ 72
323 #endif
324 #if defined(__ARM_ARCH_7M__)
325 # define __ARM_ARCH__ 73
326 #endif
327 
328 #if defined(__ARM_ARCH__) && (__ARM_ARCH__ >= 52)
329 /* tested on ARMv6 (arm1136j-s), Nokia N800 CPU */
330 #define pld(addr, off)                                                  \
331    __asm__("pld [%[address], %[offset]]"::                              \
332            [address] "r" (addr), [offset] "i" (off))
333 #else
334 #define pld(addr, off)
335 #endif /* __ARMEL__ */
336 
337 // these here are in config.h - just here for documentation
338 //#ifdef __ARM_ARCH__
339 // *IF* you enable pixman, this determines which things pixman will do
340 ////#define PIXMAN_FONT               1
341 ////#define PIXMAN_RECT               1
342 ////#define PIXMAN_LINE               1
343 ////#define PIXMAN_POLY               1
344 //#define PIXMAN_IMAGE              1
345 //#define PIXMAN_IMAGE_SCALE_SAMPLE 1
346 //#endif
347 // not related to pixman but an alternate rotate code
348 //#define TILE_ROTATE               1
349 
350 #define TILE_CACHE_LINE_SIZE      64
351 
352 #define RGBA_PLANE_MAX 3
353 
354 /*****************************************************************************/
355 
356 #define UNROLL2(op...) op op
357 #define UNROLL4(op...) UNROLL2(op) UNROLL2(op)
358 #define UNROLL8(op...) UNROLL4(op) UNROLL4(op)
359 #define UNROLL16(op...) UNROLL8(op) UNROLL8(op)
360 
361 #define UNROLL8_PLD_WHILE(start, size, end, op)         \
362     pld(start, 0);                                      \
363     end = start + (size & ~7);                          \
364     while (start < end)                                 \
365         {                                               \
366             pld(start, 32);                             \
367             UNROLL8(op);                                \
368         }                                               \
369     end += (size & 7);                                  \
370     pld(start, 32);                                     \
371     while (start <  end)                                \
372         {                                               \
373         op;                                             \
374         }
375 
376 /*****************************************************************************/
377 
378 #include "../file/evas_module.h"
379 
380 #include "evas_common_types.h"
381 
382 typedef struct _Image_Entry             Image_Entry;
383 typedef struct _Image_Entry_Flags       Image_Entry_Flags;
384 typedef struct _Image_Entry_Frame       Image_Entry_Frame;
385 typedef struct _Image_Timestamp         Image_Timestamp;
386 typedef struct _Engine_Image_Entry      Engine_Image_Entry;
387 typedef struct _Evas_Cache_Target       Evas_Cache_Target;
388 typedef struct _Evas_Preload_Pthread    Evas_Preload_Pthread;
389 
390 #ifdef BUILD_PIPE_RENDER
391 typedef struct _RGBA_Pipe_Op          RGBA_Pipe_Op;
392 typedef struct _RGBA_Pipe             RGBA_Pipe;
393 typedef struct _RGBA_Pipe_Thread_Info RGBA_Pipe_Thread_Info;
394 #endif
395 typedef struct _RGBA_Image            RGBA_Image;
396 typedef struct _RGBA_Draw_Context     RGBA_Draw_Context;
397 typedef struct _RGBA_Polygon_Point    RGBA_Polygon_Point;
398 typedef struct _RGBA_Map_Point        RGBA_Map_Point;
399 typedef struct _RGBA_Map              RGBA_Map;
400 typedef struct _RGBA_Gfx_Compositor   RGBA_Gfx_Compositor;
401 typedef struct _RGBA_Image_Data_Map   RGBA_Image_Data_Map;
402 
403 typedef struct _Cutout_Rect             Cutout_Rect;
404 typedef struct _Cutout_Rects            Cutout_Rects;
405 
406 typedef struct _Convert_Pal             Convert_Pal;
407 
408 typedef struct _Tilebuf                 Tilebuf;
409 typedef struct _Tilebuf_Rect            Tilebuf_Rect;
410 
411 #ifndef NEWTILER
412 typedef struct _Tilebuf_Tile            Tilebuf_Tile;
413 #endif
414 
415 typedef struct _Evas_Common_Transform        Evas_Common_Transform;
416 
417 // RGBA_Map_Point
418 // all coords are 20.12
419 // fp type - an int for now
420 typedef int FPc;
421 // fp # of bits of float accuracy
422 #define FP 8
423 // fp half (half of an fp unit)
424 #define FPH (1 << (FP - 1))
425 // one fp unit
426 #define FP1 (1 << (FP))
427 
428 typedef void (*Gfx_Func_Copy)    (DATA32 *src, DATA32 *dst, int len);
429 
430 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);
431 
432 typedef void (*Evas_Render_Done_Cb)(void *);
433 
434 #include "../cache/evas_cache.h"
435 #include "../common/evas_font_draw.h"
436 
437 /*****************************************************************************/
438 
439 typedef void (*Evas_Thread_Command_Cb)(void *data);
440 typedef struct _Evas_Thread_Command Evas_Thread_Command;
441 
442 struct _Evas_Thread_Command
443 {
444    Evas_Thread_Command_Cb cb;
445    void *data;
446 };
447 
448 /*****************************************************************************/
449 
450 typedef enum _RGBA_Image_Flags
451 {
452    RGBA_IMAGE_NOTHING       = (0),
453 /*    RGBA_IMAGE_HAS_ALPHA     = (1 << 0), */
454    RGBA_IMAGE_IS_DIRTY      = (1 << 1),
455    RGBA_IMAGE_INDEXED       = (1 << 2),
456    /* RGBA_IMAGE_ALPHA_ONLY    = (1 << 3), */
457    RGBA_IMAGE_ALPHA_TILES   = (1 << 4),
458 /*    RGBA_IMAGE_ALPHA_SPARSE  = (1 << 5), */
459 /*    RGBA_IMAGE_LOADED        = (1 << 6), */
460 /*    RGBA_IMAGE_NEED_DATA     = (1 << 7) */
461    RGBA_IMAGE_TODO_LOAD     = (1 << 8),
462 } RGBA_Image_Flags;
463 
464 typedef enum _Convert_Pal_Mode
465 {
466    PAL_MODE_NONE,
467    PAL_MODE_MONO,
468    PAL_MODE_GRAY4,
469    PAL_MODE_GRAY16,
470    PAL_MODE_GRAY64,
471    PAL_MODE_GRAY256,
472    PAL_MODE_RGB111,
473    PAL_MODE_RGB121,
474    PAL_MODE_RGB221,
475    PAL_MODE_RGB222,
476    PAL_MODE_RGB232,
477    PAL_MODE_RGB332,
478    PAL_MODE_RGB666,
479    PAL_MODE_LAST
480 } Convert_Pal_Mode;
481 
482 typedef enum _CPU_Features
483 {
484    CPU_FEATURE_C       = 0,
485    CPU_FEATURE_MMX     = (1 << 0),
486    CPU_FEATURE_MMX2    = (1 << 1),
487    CPU_FEATURE_SSE     = (1 << 2),
488    CPU_FEATURE_ALTIVEC = (1 << 3),
489    CPU_FEATURE_VIS     = (1 << 4),
490    CPU_FEATURE_VIS2    = (1 << 5),
491    CPU_FEATURE_NEON    = (1 << 6),
492    CPU_FEATURE_SSE3    = (1 << 7),
493    CPU_FEATURE_SVE     = (1 << 8)
494 } CPU_Features;
495 
496 /*****************************************************************************/
497 
498 struct _Image_Entry_Flags
499 {
500    Eina_Bool loaded        : 1;
501    Eina_Bool in_progress   : 1;
502    Eina_Bool dirty         : 1;
503    Eina_Bool activ         : 1;
504 
505    Eina_Bool need_data     : 1;
506    Eina_Bool lru_nodata    : 1;
507    Eina_Bool cached        : 1;
508    Eina_Bool alpha         : 1;
509 
510    Eina_Bool lru           : 1;
511    Eina_Bool alpha_sparse  : 1;
512    Eina_Bool preload_done  : 1;
513    Eina_Bool delete_me     : 1;
514 
515    Eina_Bool pending       : 1;
516    Eina_Bool rotated       : 1;
517    Eina_Bool unload_cancel : 1;
518    Eina_Bool given_mmap    : 1;
519 
520    Eina_Bool updated_data  : 1;
521    Eina_Bool flipped       : 1;
522    Eina_Bool textured      : 1;
523    Eina_Bool preload_pending : 1;
524 };
525 
526 struct _Image_Entry_Frame
527 {
528    int       index;
529    DATA32   *data;     /* frame decoding data */
530    void     *info;     /* special image type info */
531    Eina_Bool loaded       : 1;
532 };
533 
534 struct _Evas_Cache_Target
535 {
536    EINA_INLIST;
537    const Eo *target;
538    void *data;
539    void (*preloaded_cb) (void *data); //Call when preloading done.
540    void *preloaded_data;
541    Eina_Bool delete_me : 1;
542    Eina_Bool preload_cancel : 1;
543 };
544 
545 struct _Image_Timestamp
546 {
547    time_t mtime;
548    off_t  size;
549    ino_t  ino;
550 #ifdef _STAT_VER_LINUX
551    unsigned long int mtime_nsec;
552 #endif
553 };
554 
555 struct _Image_Entry
556 {
557    EINA_INLIST;
558 
559    int                    magic;
560 
561    Evas_Cache_Image      *cache;
562 
563    const char            *cache_key;
564 
565    const char            *file;
566    const char            *key;
567 
568    Evas_Cache_Target     *targets;
569    Evas_Preload_Pthread  *preload;
570 
571    Image_Timestamp        tstamp;
572 
573    int                    references;
574 
575 #ifdef BUILD_PIPE_RENDER
576    RGBA_Pipe             *pipe;
577 #endif
578 
579    Evas_Image_Load_Opts   load_opts;
580    Evas_Colorspace        space;
581    const Evas_Colorspace *cspaces; // owned by the loader, live as long as the loader
582    Evas_Image_Orient      orient;
583 
584    unsigned int           w;
585    unsigned int           h;
586 
587    unsigned char          scale;
588 
589    unsigned char          need_unload : 1;
590    unsigned char          load_failed : 1;
591    unsigned char          need_data : 1;
592 
593    struct
594      {
595         unsigned int w;
596         unsigned int h;
597      } allocated;
598 
599    struct
600      {
601         unsigned char l, r, t, b;
602      } borders; // Duplicated borders for use by GL engines.
603 
604    struct
605      {
606         Evas_Module          *module;
607         Evas_Image_Load_Func *loader;
608      } info;
609 
610    SLK(lock);
611    SLK(lock_cancel);
612 
613    /* for animation feature */
614    Evas_Image_Animated   animated;
615 
616    /* Reference to the file */
617    Eina_File             *f;
618    void                  *loader_data;
619 
620    Image_Entry_Flags      flags;
621    Evas_Image_Scale_Hint  scale_hint;
622    void                  *data1, *data2;
623    int                    server_id;
624    int                    connect_num;
625    int                    channel;
626    Evas_Load_Error        load_error;
627 
628    struct {
629       struct {
630          uint8_t *region;
631       } horizontal, vertical;
632    } stretch;
633 
634    Eina_Rectangle content;
635 };
636 
637 struct _Engine_Image_Entry
638 {
639    EINA_INLIST;
640 
641    /* Upper Engine data. */
642    Image_Entry                  *src;
643 
644    /* Cache stuff. */
645    Evas_Cache_Engine_Image      *cache;
646    const char                   *cache_key;
647 
648    struct
649    {
650      Eina_Bool                   cached : 1;
651      Eina_Bool                   activ : 1;
652      Eina_Bool                   dirty : 1;
653      Eina_Bool                   loaded : 1;
654      Eina_Bool                   need_parent : 1;
655    } flags;
656 
657    int                           references;
658    int                           w;
659    int                           h;
660 };
661 
662 struct _Cutout_Rect
663 {
664    int               x, y, w, h;
665 };
666 
667 struct _Cutout_Rects
668 {
669    Cutout_Rect      *rects;
670    int               active;
671    int               max;
672    struct {
673       int            x, w, y, h;
674    } last_add;
675 };
676 
677 struct _Evas_Common_Transform
678 {
679    float  mxx, mxy, mxz;
680    float  myx, myy, myz;
681    float  mzx, mzy, mzz;
682 };
683 
684 struct _RGBA_Draw_Context
685 {
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, int w, int h);
691          void *(*gl_image_new) (void *gc, RGBA_Font_Glyph *fg, int alpha, Evas_Colorspace cspace);
692          void  (*gl_image_free) (void *image);
693          void  (*gl_image_draw) (void *gc, void *im, int dx, int dy, int dw, int dh, int smooth);
694          void  (*gl_garbage_collector) (void *gc, float ratio, int *texture_size, int *atlas_size);
695       } func;
696       void *data;
697    } font_ext;
698    struct {
699       int x, y, w, h;
700    } cutout_target;
701    struct RGBA_Draw_Context_clip {
702       Evas_Public_Data *evas; // for async unref
703       void  *mask; // RGBA_Image (SW) or Evas_GL_Image (GL)
704       int    x, y, w, h;
705       int    mask_x, mask_y;
706       Eina_Bool use : 1;
707       Eina_Bool async : 1;
708       Eina_Bool mask_color : 1; // true if masking with color (eg. filters)
709    } clip;
710    struct {
711 #ifdef HAVE_PIXMAN
712       pixman_image_t  *pixman_color_image;
713 #endif
714       DATA32 col;
715    } col;
716    Cutout_Rects cutout;
717    struct {
718       DATA32    col;
719       Eina_Bool use : 1;
720    } mul;
721    struct {
722       Cutout_Rects *rects;
723       unsigned int  used;
724    } cache;
725    struct {
726       unsigned char color_space;
727    } interpolation;
728    unsigned char render_op;
729    unsigned char anti_alias : 1;
730 };
731 
732 #ifdef BUILD_PIPE_RENDER
733 #include "../common/evas_map_image.h"
734 
735 struct _RGBA_Pipe_Op
736 {
737    RGBA_Draw_Context         context;
738    Eina_Bool               (*prepare_func) (void *data, RGBA_Image *dst, RGBA_Pipe_Op *op);
739    void                    (*op_func) (RGBA_Image *dst, const RGBA_Pipe_Op *op, const RGBA_Pipe_Thread_Info *info);
740    void                    (*free_func) (RGBA_Pipe_Op *op);
741    Cutout_Rects             *rects;
742 
743    union {
744       struct {
745 	 int                 x, y, w, h;
746       } rect;
747       struct {
748 	 int                 x0, y0, x1, y1;
749       } line;
750       struct {
751          int                 x, y;
752 	 RGBA_Polygon_Point *points;
753       } poly;
754       struct {
755 	 int                 x, y;
756          Evas_Text_Props    *intl_props;
757          RGBA_Gfx_Func       func;
758       } text;
759       struct {
760 	 RGBA_Image         *src;
761 	 int                 sx, sy, sw, sh, dx, dy, dw, dh;
762 	 int                 smooth;
763 	 char               *text;
764       } image;
765       struct {
766 	 RGBA_Image         *src;
767 	 RGBA_Map	    *m;
768 	 int                 npoints;
769 	 int                 smooth;
770 	 int                 level;
771       } map;
772    } op;
773 
774    Eina_Bool                 render : 1;
775 };
776 
777 #define PIPE_LEN 256
778 
779 struct _RGBA_Pipe
780 {
781    EINA_INLIST;
782    int               op_num;
783    RGBA_Pipe_Op      op[PIPE_LEN];
784 };
785 
786 struct _RGBA_Pipe_Thread_Info
787 {
788    EINA_INLIST;
789    Eina_Rectangle area;
790 };
791 #endif
792 
793 struct _RGBA_Image_Data_Map {
794    EINA_INLIST;
795    unsigned char  *baseptr;
796    Eina_Rw_Slice   slice;
797    int             stride; // in bytes
798    int             rx, ry, rw, rh; // actual map region
799    int             plane;
800    Evas_Colorspace cspace;
801    Eina_Bool       allocated; // ptr is malloc() for cow or cspace conv
802    Efl_Gfx_Buffer_Access_Mode mode;
803 };
804 
805 struct _RGBA_Image
806 {
807    Image_Entry          cache_entry;
808    RGBA_Image_Flags     flags;
809    void                *extended_info;
810 
811    /* Colorspace stuff. */
812    struct {
813       void              *data;
814       Eina_Bool          no_free : 1;
815       Eina_Bool          dirty : 1;
816    } cs;
817 
818    /* RGBA stuff */
819    struct {
820       union {
821          DATA32         *data;    /* Normal image */
822          DATA8          *data8;   /* Alpha Mask stuff */
823       };
824       Eina_Bool          no_free : 1;
825    } image;
826 
827    struct {
828       SLK(lock);
829       Eina_List *list;
830       Eina_Hash *hash;
831       unsigned long long orig_usage;
832       unsigned long long usage_count;
833       int populate_count;
834       unsigned long long newest_usage;
835       unsigned long long newest_usage_count;
836    } cache;
837 
838 #ifdef HAVE_PIXMAN
839    struct {
840       pixman_image_t *im;
841    } pixman;
842 #endif
843    struct {
844       void   *data; //Evas_Native_Surface ns;
845       struct {
846         void (*bind) (void *image, int x, int y, int w, int h);
847         void (*unbind) (void *image);
848         void (*free) (void *image);
849       } func;
850    } native;
851 
852    /* data map/unmap */
853    RGBA_Image_Data_Map *maps;
854 };
855 
856 struct _RGBA_Polygon_Point
857 {
858    EINA_INLIST;
859    int               x, y;
860 };
861 
862 struct _RGBA_Map_Point
863 {
864    FPc x, y; // x, y screenspace
865    float fx, fy, fz; // x, y, z in floats
866 //   FPc x3, y3; // x, y 3d space
867    FPc z; // z in world space. optional
868    FPc u, v; // u, v in tex coords
869    DATA32 col; // color at this point
870    // for perspective correctness - only point 0 has relevant info
871    FPc px, py, z0, foc;
872 };
873 
874 struct _RGBA_Map
875 {
876    void *engine_data;
877 
878    struct {
879       int w, h;
880    } image, uv;
881 
882    int x, y;
883    int count;
884 
885    RGBA_Map_Point pts[1];
886 };
887 
888 struct _RGBA_Gfx_Compositor
889 {
890    const char *name;
891 
892    void              (*init)(void);
893    void              (*shutdown)(void);
894 
895    RGBA_Gfx_Func  (*composite_pixel_span_get)(Eina_Bool src_alpha, Eina_Bool src_sparse_alpha, Eina_Bool dst_alpha, int pixels);
896    RGBA_Gfx_Func  (*composite_color_span_get)(DATA32 col, Eina_Bool dst_alpha, int pixels);
897    RGBA_Gfx_Func  (*composite_pixel_color_span_get)(Eina_Bool src_alpha, Eina_Bool src_sparse_alpha, DATA32 col, Eina_Bool dst_alpha, int pixels);
898    RGBA_Gfx_Func  (*composite_mask_color_span_get)(DATA32 col, Eina_Bool dst_alpha, int pixels);
899    RGBA_Gfx_Func  (*composite_pixel_mask_span_get)(Eina_Bool src_alpha, Eina_Bool src_sparse_alpha, Eina_Bool dst_alpha, int pixels);
900 
901    RGBA_Gfx_Pt_Func  (*composite_pixel_pt_get)(Eina_Bool src_alpha, Eina_Bool dst_alpha);
902    RGBA_Gfx_Pt_Func  (*composite_color_pt_get)(DATA32 col, Eina_Bool dst_alpha);
903    RGBA_Gfx_Pt_Func  (*composite_pixel_color_pt_get)(Eina_Bool src_alpha, DATA32 col, Eina_Bool dst_alpha);
904    RGBA_Gfx_Pt_Func  (*composite_mask_color_pt_get)(DATA32 col, Eina_Bool dst_alpha);
905    RGBA_Gfx_Pt_Func  (*composite_pixel_mask_pt_get)(Eina_Bool src_alpha, Eina_Bool dst_alpha);
906 };
907 
908 #ifndef NEWTILER
909 typedef struct list_node list_node_t;
910 typedef struct list list_t;
911 typedef struct rect rect_t;
912 typedef struct rect_node rect_node_t;
913 
914 struct list_node
915 {
916     struct list_node *next;
917 };
918 
919 struct list
920 {
921     struct list_node *head;
922     struct list_node *tail;
923 };
924 
925 struct rect
926 {
927     int left;
928     int top;
929     int right;
930     int bottom;
931     int width;
932     int height;
933     int area;
934 };
935 
936 struct rect_node
937 {
938     struct list_node _lst;
939     struct rect rect;
940 };
941 #endif
942 
943 struct _Tilebuf
944 {
945    int outbuf_w, outbuf_h;
946 #ifdef NEWTILER
947    void *region;
948 #else
949    struct {
950       short w, h;
951    } tile_size;
952    list_t rects;
953    struct {
954       int x, y, w, h;
955    } prev_add, prev_del;
956    Eina_Bool strict_tiles : 1;
957    Eina_Bool need_merge : 1;
958 #endif
959 };
960 
961 #ifndef NEWTILER
962 struct _Tilebuf_Tile
963 {
964    Eina_Bool redraw : 1;
965 };
966 #endif
967 
968 struct _Tilebuf_Rect
969 {
970    EINA_INLIST;
971    int               x, y, w, h;
972 };
973 
974 struct _Convert_Pal
975 {
976    int               references;
977    int               count;
978    Convert_Pal_Mode  colors;
979    DATA8            *lookup;
980    void             *data;
981 };
982 
983 /****/
984 
985 /*****************************************************************************/
986 #include "evas_macros.h"
987 
988 #ifndef A_VAL
989 #ifndef WORDS_BIGENDIAN
990 /* x86 */
991 #define A_VAL(p) (((DATA8 *)(p))[3])
992 #define R_VAL(p) (((DATA8 *)(p))[2])
993 #define G_VAL(p) (((DATA8 *)(p))[1])
994 #define B_VAL(p) (((DATA8 *)(p))[0])
995 #define AR_VAL(p) ((DATA16 *)(p)[1])
996 #define GB_VAL(p) ((DATA16 *)(p)[0])
997 #else
998 /* ppc */
999 #define A_VAL(p) (((DATA8 *)(p))[0])
1000 #define R_VAL(p) (((DATA8 *)(p))[1])
1001 #define G_VAL(p) (((DATA8 *)(p))[2])
1002 #define B_VAL(p) (((DATA8 *)(p))[3])
1003 #define AR_VAL(p) ((DATA16 *)(p)[0])
1004 #define GB_VAL(p) ((DATA16 *)(p)[1])
1005 #endif
1006 #endif
1007 
1008 #define RGB_JOIN(r,g,b) \
1009         (((r) << 16) + ((g) << 8) + (b))
1010 
1011 #define ARGB_JOIN(a,r,g,b) \
1012         (((a) << 24) + ((r) << 16) + ((g) << 8) + (b))
1013 
1014 #include "evas_blend_ops.h"
1015 
1016 #define _EVAS_RENDER_FILL        -1
1017 #define _EVAS_RENDER_BLEND        0
1018 #define _EVAS_RENDER_BLEND_REL    1
1019 #define _EVAS_RENDER_COPY         2
1020 #define _EVAS_RENDER_COPY_REL     3
1021 #define _EVAS_RENDER_ADD          4
1022 #define _EVAS_RENDER_ADD_REL      5
1023 #define _EVAS_RENDER_SUB          6
1024 #define _EVAS_RENDER_SUB_REL      7
1025 #define _EVAS_RENDER_TINT         8
1026 #define _EVAS_RENDER_TINT_REL     9
1027 #define _EVAS_RENDER_MASK         10
1028 #define _EVAS_RENDER_MUL          11
1029 #define _EVAS_RENDER_CLIP         12
1030 
1031 #define _EVAS_TEXTURE_REFLECT           0
1032 #define _EVAS_TEXTURE_REPEAT            1
1033 #define _EVAS_TEXTURE_RESTRICT          2
1034 #define _EVAS_TEXTURE_RESTRICT_REFLECT  3
1035 #define _EVAS_TEXTURE_RESTRICT_REPEAT   4
1036 #define _EVAS_TEXTURE_PAD               5
1037 
1038 #define _EVAS_COLOR_SPACE_ARGB    0
1039 #define _EVAS_COLOR_SPACE_AHSV    1
1040 
1041 /*****************************************************************************/
1042 
1043 #define SCALE_SIZE_MAX ((1 << 15) - 1)
1044 
1045 #ifdef __cplusplus
1046 extern "C" {
1047 #endif
1048 
1049 /****/
1050 EAPI void evas_common_init                                   (void);
1051 EAPI void evas_common_shutdown                               (void);
1052 
1053 EAPI void evas_common_cpu_init                          (void);
1054 
1055 int  evas_common_cpu_have_cpuid                         (void);
1056 int  evas_common_cpu_has_feature                        (unsigned int feature);
1057 EAPI void evas_common_cpu_can_do                        (int *mmx, int *sse, int *sse2);
1058 EAPI void evas_common_cpu_end_opt                       (void);
1059 
1060 /****/
1061 #include "../common/evas_blend.h"
1062 
1063 EAPI Gfx_Func_Copy        evas_common_draw_func_copy_get        (int pixels, int reverse);
1064 
1065 /****/
1066 #include "../common/evas_convert_color.h"
1067 #include "../common/evas_convert_colorspace.h"
1068 #include "../common/evas_convert_main.h"
1069 #include "../common/evas_convert_yuv.h"
1070 #include "../common/evas_scale_main.h"
1071 #include "../common/evas_scale_smooth.h"
1072 #include "../common/evas_scale_span.h"
1073 
1074 /****/
1075 #include "../common/evas_image.h"
1076 
1077 /****/
1078 #include "../common/evas_line.h"
1079 #include "../common/evas_polygon.h"
1080 #include "../common/evas_rectangle.h"
1081 
1082 /****/
1083 EAPI void     evas_common_blit_init               (void);
1084 
1085 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);
1086 
1087 /****/
1088 
1089 /****/
1090 EAPI void          evas_common_tilebuf_init               (void);
1091 
1092 EAPI Tilebuf      *evas_common_tilebuf_new               (int w, int h);
1093 EAPI void          evas_common_tilebuf_free              (Tilebuf *tb);
1094 EAPI void          evas_common_tilebuf_set_tile_size     (Tilebuf *tb, int tw, int th);
1095 EAPI void          evas_common_tilebuf_get_tile_size     (Tilebuf *tb, int *tw, int *th);
1096 EAPI void          evas_common_tilebuf_tile_strict_set   (Tilebuf *tb, Eina_Bool strict);
1097 EAPI int           evas_common_tilebuf_add_redraw        (Tilebuf *tb, int x, int y, int w, int h);
1098 EAPI int           evas_common_tilebuf_del_redraw        (Tilebuf *tb, int x, int y, int w, int h);
1099 EAPI int           evas_common_tilebuf_add_motion_vector (Tilebuf *tb, int x, int y, int w, int h, int dx, int dy, int alpha);
1100 EAPI void          evas_common_tilebuf_clear             (Tilebuf *tb);
1101 EAPI Tilebuf_Rect *evas_common_tilebuf_get_render_rects  (Tilebuf *tb);
1102 EAPI void          evas_common_tilebuf_free_render_rects (Tilebuf_Rect *rects);
1103 
1104 /*
1105 Regionbuf    *evas_common_regionbuf_new       (int w, int h);
1106 void          evas_common_regionbuf_free      (Regionbuf *rb);
1107 void          evas_common_regionbuf_clear     (Regionbuf *rb);
1108 void          evas_common_regionbuf_span_add  (Regionbuf *rb, int x1, int x2, int y);
1109 void          evas_common_regionbuf_span_del  (Regionbuf *rb, int x1, int x2, int y);
1110 Tilebuf_Rect *evas_common_regionbuf_rects_get (Regionbuf *rb);
1111 */
1112 
1113 /****/
1114 #include "../common/evas_draw.h"
1115 
1116 #include "../common/evas_map_image.h"
1117 
1118 /****/
1119 #include "../common/evas_pipe.h"
1120 
1121 EAPI void         evas_thread_queue_wait(void);
1122 
1123 EAPI int          evas_async_events_process_blocking(void);
1124 void	          evas_render_rendering_wait(Evas_Public_Data *evas);
1125 void              evas_all_sync(void);
1126 
1127 int               evas_thread_init(void);
1128 int               evas_thread_shutdown(void);
1129 EAPI void         evas_thread_cmd_enqueue(Evas_Thread_Command_Cb cb, void *data);
1130 EAPI void         evas_thread_queue_flush(Evas_Thread_Command_Cb cb, void *data);
1131 
1132 typedef enum _Evas_Render_Mode
1133 {
1134    EVAS_RENDER_MODE_UNDEF,
1135    EVAS_RENDER_MODE_SYNC,
1136    EVAS_RENDER_MODE_ASYNC_INIT,
1137    EVAS_RENDER_MODE_ASYNC_END,
1138 } Evas_Render_Mode;
1139 
1140 /****/
1141 
1142 void evas_common_rgba_image_scalecache_items_ref(Image_Entry *ie, Eina_Array *ret);
1143 void evas_common_rgba_image_scalecache_item_unref(Image_Entry *ie);
1144 
1145 // Generic Cache
1146 typedef struct _Generic_Cache          Generic_Cache;
1147 typedef struct _Generic_Cache_Entry    Generic_Cache_Entry;
1148 
1149 struct _Generic_Cache_Entry
1150 {
1151    void         *key;     // pointer
1152    void         *data; // engine image
1153    int           ref;
1154 };
1155 
1156 typedef void (*Generic_Cache_Free)(void *user_data, void *data);
1157 
1158 struct _Generic_Cache
1159 {
1160    Eina_Hash          *hash;
1161    Eina_List          *lru_list;
1162    void               *user_data;
1163    Generic_Cache_Free  free_func;
1164 };
1165 
1166 EAPI Generic_Cache* generic_cache_new(void *user_data, Generic_Cache_Free func);
1167 EAPI void generic_cache_destroy(Generic_Cache *cache);
1168 EAPI void generic_cache_dump(Generic_Cache *cache);
1169 EAPI void generic_cache_data_set(Generic_Cache *cache, void *key, void *data);
1170 EAPI void *generic_cache_data_get(Generic_Cache *cache, void *key);
1171 EAPI void generic_cache_data_drop(Generic_Cache *cache, void *key);
1172 
1173 /*****************************************************************************/
1174 
1175 #ifdef __cplusplus
1176 }
1177 #endif
1178 
1179 #undef EAPI
1180 #define EAPI
1181 
1182 #endif
1183