merged evas image masking code from brett
[framework/uifw/evas.git] / src / lib / engines / common / evas_rectangle_main.c
1 #include "evas_common.h"
2 #include "evas_blend_private.h"
3
4 static void rectangle_draw_internal(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int y, int w, int h);
5
6 EAPI void
7 evas_common_rectangle_init(void)
8 {
9 }
10
11 EAPI void
12 evas_common_rectangle_draw(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int y, int w, int h)
13 {
14    Cutout_Rects *rects;
15    Cutout_Rect  *r;
16    int          c, cx, cy, cw, ch;
17    int          i;
18    /* handle cutouts here! */
19
20    if ((w <= 0) || (h <= 0)) return;
21    if (!(RECTS_INTERSECT(x, y, w, h, 0, 0, dst->cache_entry.w, dst->cache_entry.h)))
22      return;
23    /* save out clip info */
24    c = dc->clip.use; cx = dc->clip.x; cy = dc->clip.y; cw = dc->clip.w; ch = dc->clip.h;
25    evas_common_draw_context_clip_clip(dc, 0, 0, dst->cache_entry.w, dst->cache_entry.h);
26    /* no cutouts - cut right to the chase */
27    if (!dc->cutout.rects)
28      {
29         rectangle_draw_internal(dst, dc, x, y, w, h);
30      }
31    else
32      {
33         evas_common_draw_context_clip_clip(dc, x, y, w, h);
34         /* our clip is 0 size.. abort */
35         if ((dc->clip.w > 0) && (dc->clip.h > 0))
36           {
37              rects = evas_common_draw_context_apply_cutouts(dc);
38              for (i = 0; i < rects->active; ++i)
39                {
40                   r = rects->rects + i;
41                   evas_common_draw_context_set_clip(dc, r->x, r->y, r->w, r->h);
42                   rectangle_draw_internal(dst, dc, x, y, w, h);
43                }
44              evas_common_draw_context_apply_clear_cutouts(rects);
45           }
46      }
47    /* restore clip info */
48    dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
49 }
50
51 static void
52 rectangle_draw_internal(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int y, int w, int h)
53 {
54    RGBA_Gfx_Func func;
55    int yy;
56    DATA32 *ptr;
57    RGBA_Image *maskobj;
58    DATA8 *mask = NULL;
59
60    RECTS_CLIP_TO_RECT(x, y, w, h, dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h);
61    if ((w <= 0) || (h <= 0)) return;
62
63    maskobj = dc->mask.mask;
64    if (maskobj)
65      {
66         func = evas_common_gfx_func_composite_mask_color_span_get(dc->col.col,
67                         dst, 1, dc->render_op);
68         mask = maskobj->mask.mask;
69      }
70    else
71       func = evas_common_gfx_func_composite_color_span_get(dc->col.col, dst, w, dc->render_op);
72    ptr = dst->image.data + (y * dst->cache_entry.w) + x;
73
74    if (!mask)
75      {
76         for (yy = 0; yy < h; yy++)
77           {
78 #ifdef EVAS_SLI
79              if (((yy + y) % dc->sli.h) == dc->sli.y)
80 #endif
81                {
82                   func(NULL, NULL, dc->col.col, ptr, w);
83                }
84              ptr += dst->cache_entry.w;
85           }
86      }
87    else
88      {
89         /* X Adjust */
90         mask += x - dc->mask.x;
91         /* Y Adjust */
92         mask += (y - dc->mask.y) * maskobj->cache_entry.w;
93         /* Draw with mask */
94         for (yy = 0; yy < h; yy++)
95           {
96 #ifdef EVAS_SLI
97              if (((yy + y) % dc->sli.h) == dc->sli.y)
98 #endif
99                {
100                   func(NULL, mask, dc->col.col, ptr, w);
101                }
102              ptr += dst->cache_entry.w;
103              mask += maskobj->cache_entry.w;
104           }
105
106      }
107 }
108
109
110 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/