2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
5 #include "evas_common.h"
6 #include "evas_convert_main.h"
9 evas_common_draw_context_cutouts_new(void)
13 rects = malloc(sizeof(Cutout_Rects));
22 evas_common_draw_context_cutouts_free(Cutout_Rects* rects)
28 evas_common_draw_context_cutouts_add(Cutout_Rects* rects,
29 int x, int y, int w, int h)
33 if (rects->max < (rects->active + 1))
36 rects->rects = realloc(rects->rects, sizeof(Cutout_Rect) * rects->max);
39 rect = rects->rects + rects->active;
50 evas_common_draw_context_cutouts_del(Cutout_Rects* rects,
53 if ((index >= 0) && (index < rects->active))
57 rect = rects->rects + index;
58 memmove(rect, rect + 1,
59 sizeof(Cutout_Rect) * (rects->active - index - 1));
65 evas_common_init(void)
67 evas_common_cpu_init();
69 evas_common_blend_init();
70 evas_common_image_init();
71 evas_common_convert_init();
72 evas_common_scale_init();
73 evas_common_rectangle_init();
74 evas_common_gradient_init();
75 evas_common_polygon_init();
76 evas_common_line_init();
77 evas_common_font_init();
78 evas_common_draw_init();
79 evas_common_tilebuf_init();
83 evas_common_shutdown(void)
85 evas_font_dir_cache_free();
86 evas_common_image_cache_free();
90 evas_common_draw_init(void)
94 EAPI RGBA_Draw_Context *
95 evas_common_draw_context_new(void)
97 RGBA_Draw_Context *dc;
99 dc = calloc(1, sizeof(RGBA_Draw_Context));
105 evas_common_draw_context_free(RGBA_Draw_Context *dc)
109 evas_common_draw_context_apply_clean_cutouts(&dc->cutout);
114 evas_common_draw_context_clear_cutouts(RGBA_Draw_Context *dc)
116 evas_common_draw_context_apply_clean_cutouts(&dc->cutout);
120 evas_common_draw_context_font_ext_set(RGBA_Draw_Context *dc,
122 void *(*gl_new) (void *data, RGBA_Font_Glyph *fg),
123 void (*gl_free) (void *ext_dat),
124 void (*gl_draw) (void *data, void *dest, void *context, RGBA_Font_Glyph *fg, int x, int y))
126 dc->font_ext.data = data;
127 dc->font_ext.func.gl_new = gl_new;
128 dc->font_ext.func.gl_free = gl_free;
129 dc->font_ext.func.gl_draw = gl_draw;
133 evas_common_draw_context_clip_clip(RGBA_Draw_Context *dc, int x, int y, int w, int h)
137 RECTS_CLIP_TO_RECT(dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h,
141 evas_common_draw_context_set_clip(dc, x, y, w, h);
145 evas_common_draw_context_set_clip(RGBA_Draw_Context *dc, int x, int y, int w, int h)
155 evas_common_draw_context_unset_clip(RGBA_Draw_Context *dc)
161 evas_common_draw_context_set_color(RGBA_Draw_Context *dc, int r, int g, int b, int a)
163 R_VAL(&(dc->col.col)) = (DATA8)r;
164 G_VAL(&(dc->col.col)) = (DATA8)g;
165 B_VAL(&(dc->col.col)) = (DATA8)b;
166 A_VAL(&(dc->col.col)) = (DATA8)a;
170 evas_common_draw_context_set_multiplier(RGBA_Draw_Context *dc, int r, int g, int b, int a)
173 R_VAL(&(dc->mul.col)) = (DATA8)r;
174 G_VAL(&(dc->mul.col)) = (DATA8)g;
175 B_VAL(&(dc->mul.col)) = (DATA8)b;
176 A_VAL(&(dc->mul.col)) = (DATA8)a;
180 evas_common_draw_context_unset_multiplier(RGBA_Draw_Context *dc)
186 evas_common_draw_context_add_cutout(RGBA_Draw_Context *dc, int x, int y, int w, int h)
190 RECTS_CLIP_TO_RECT(x, y, w, h,
191 dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h);
192 if ((w < 1) || (h < 1)) return;
194 evas_common_draw_context_cutouts_add(&dc->cutout, x, y, w, h);
198 evas_common_draw_context_cutout_split(Cutout_Rects* res, int index, Cutout_Rect *split)
200 /* 1 input rect, multiple out */
201 Cutout_Rect in = res->rects[index];
203 /* this is to save me a LOT of typing */
205 #define INX2 (in.x + in.w)
206 #define SPX1 (split->x)
207 #define SPX2 (split->x + split->w)
209 #define INY2 (in.y + in.h)
210 #define SPY1 (split->y)
211 #define SPY2 (split->y + split->h)
212 #define X1_IN (in.x < split->x)
213 #define X2_IN ((in.x + in.w) > (split->x + split->w))
214 #define Y1_IN (in.y < split->y)
215 #define Y2_IN ((in.y + in.h) > (split->y + split->h))
216 #define R_NEW(_r, _x, _y, _w, _h) { evas_common_draw_context_cutouts_add(_r, _x, _y, _w, _h); }
217 if (!RECTS_INTERSECT(in.x, in.y, in.w, in.h,
218 split->x, split->y, split->w, split->h))
220 /* No colision => no clipping, don't touch it. */
224 /* S = split (ie cut out rect) */
225 /* +--+ = in (rect to be cut) */
235 if (X1_IN && X2_IN && Y1_IN && Y2_IN)
237 R_NEW(res, in.x, in.y, in.w, SPY1 - in.y);
238 R_NEW(res, in.x, SPY1, SPX1 - in.x, SPY2 - SPY1);
239 R_NEW(res, SPX2, SPY1, INX2 - SPX2, SPY2 - SPY1);
240 /* out => (in.x, SPY2, in.w, INY2 - SPY2) */
241 res->rects[index].h = INY2 - SPY2;
242 res->rects[index].y = SPY2;
253 if (!X1_IN && !X2_IN && !Y1_IN && !Y2_IN)
255 evas_common_draw_context_cutouts_del(res, index);
266 if (!X1_IN && X2_IN && !Y1_IN && !Y2_IN)
268 /* in => (SPX2, in.y, INX2 - SPX2, in.h) */
269 res->rects[index].w = INX2 - SPX2;
270 res->rects[index].x = SPX2;
281 if (X1_IN && X2_IN && !Y1_IN && !Y2_IN)
283 R_NEW(res, in.x, in.y, SPX1 - in.x, in.h);
284 /* in => (SPX2, in.y, INX2 - SPX2, in.h) */
285 res->rects[index].w = INX2 - SPX2;
286 res->rects[index].x = SPX2;
297 if (X1_IN && !X2_IN && !Y1_IN && !Y2_IN)
299 /* in => (in.x, in.y, SPX1 - in.x, in.h) */
300 res->rects[index].w = SPX1 - in.x;
311 if (!X1_IN && !X2_IN && !Y1_IN && Y2_IN)
313 /* in => (in.x, SPY2, in.w, INY2 - SPY2) */
314 res->rects[index].h = INY2 - SPY2;
315 res->rects[index].y = SPY2;
326 if (!X1_IN && !X2_IN && Y1_IN && Y2_IN)
328 R_NEW(res, in.x, SPY2, in.w, INY2 - SPY2);
329 /* in => (in.x, in.y, in.w, SPY1 - in.y) */
330 res->rects[index].h = SPY1 - in.y;
341 if (!X1_IN && !X2_IN && Y1_IN && !Y2_IN)
343 /* in => (in.x, in.y, in.w, SPY1 - in.y) */
344 res->rects[index].h = SPY1 - in.y;
355 if (!X1_IN && X2_IN && !Y1_IN && Y2_IN)
357 R_NEW(res, SPX2, in.y, INX2 - SPX2, SPY2 - in.y);
358 /* in => (in.x, SPY2, in.w, INY2 - SPY2) */
359 res->rects[index].h = INY2 - SPY2;
360 res->rects[index].y = SPY2;
371 if (X1_IN && X2_IN && !Y1_IN && Y2_IN)
373 R_NEW(res, in.x, in.y, SPX1 - in.x, SPY2 - in.y);
374 R_NEW(res, SPX2, in.y, INX2 - SPX2, SPY2 - in.y);
375 /* in => (in.x, SPY2, in.w, INY2 - SPY2) */
376 res->rects[index].h = INY2 - SPY2;
377 res->rects[index].y = SPY2;
388 if (X1_IN && !X2_IN && !Y1_IN && Y2_IN)
390 R_NEW(res, in.x, in.y, SPX1 - in.x, SPY2 - in.y);
391 /* in => (in.x, SPY2, in.w, INY2 - SPY2) */
392 res->rects[index].h = INY2 - SPY2;
393 res->rects[index].y = SPY2;
404 if (!X1_IN && X2_IN && Y1_IN && Y2_IN)
406 R_NEW(res, in.x, SPY2, in.w, INY2 - SPY2);
407 R_NEW(res, SPX2, SPY1, INX2 - SPX2, SPY2 - SPY1);
408 /* in => (in.x, SPY2, in.w, INY2 - SPY2) */
409 res->rects[index].h = SPY1 - in.y;
420 if (X1_IN && !X2_IN && Y1_IN && Y2_IN)
422 R_NEW(res, in.x, SPY2, in.w, INY2 - SPY2);
423 R_NEW(res, in.x, SPY1, SPX1 - in.x, SPY2 - SPY1);
424 /* in => (in.x, in.y, in.w, SPY1 - in.y) */
425 res->rects[index].h = SPY1 - in.y;
436 if (!X1_IN && X2_IN && Y1_IN && !Y2_IN)
438 R_NEW(res, SPX2, SPY1, INX2 - SPX2, INY2 - SPY1);
439 /* in => (in.x, in.y, in.w, SPY1 - in.y) */
440 res->rects[index].h = SPY1 - in.y;
451 if (X1_IN && X2_IN && Y1_IN && !Y2_IN)
453 R_NEW(res, in.x, SPY1, SPX1 - in.x, INY2 - SPY1);
454 R_NEW(res, SPX2, SPY1, INX2 - SPX2, INY2 - SPY1);
455 /* in => (in.x, in.y, in.w, SPY1 - in.y) */
456 res->rects[index].h = SPY1 - in.y;
467 if (X1_IN && !X2_IN && Y1_IN && !Y2_IN)
469 R_NEW(res, in.x, SPY1, SPX1 - in.x, INY2 - SPY1);
470 /* in => (in.x, in.y, in.w, SPY1 - in.y) */
471 res->rects[index].h = SPY1 - in.y;
474 evas_common_draw_context_cutouts_del(res, index);
492 evas_common_draw_context_apply_cutouts(RGBA_Draw_Context *dc)
498 if (!dc->clip.use) return NULL;
499 if ((dc->clip.w <= 0) || (dc->clip.h <= 0)) return NULL;
501 res = evas_common_draw_context_cutouts_new();
502 evas_common_draw_context_cutouts_add(res, dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h);
504 for (i = 0; i < dc->cutout.active; ++i)
506 /* Don't loop on the element just added to the list as they are already correctly clipped. */
507 int active = res->active;
509 for (j = 0; j < active; )
511 if (evas_common_draw_context_cutout_split(res, j, dc->cutout.rects + i))
521 evas_common_draw_context_apply_clear_cutouts(Cutout_Rects* rects)
523 evas_common_draw_context_apply_clean_cutouts(rects);
528 evas_common_draw_context_apply_clean_cutouts(Cutout_Rects* rects)
537 evas_common_draw_context_set_anti_alias(RGBA_Draw_Context *dc , unsigned char aa)
539 dc->anti_alias = !!aa;
543 evas_common_draw_context_set_color_interpolation(RGBA_Draw_Context *dc, int color_space)
545 dc->interpolation.color_space = color_space;
549 evas_common_draw_context_set_render_op(RGBA_Draw_Context *dc , int op)
555 evas_common_draw_context_set_sli(RGBA_Draw_Context *dc, int y, int h)