aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/lib/engines/common/evas_draw_main.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-04 18:41:13 +1000
committerDavid Walter Seikel2012-01-04 18:41:13 +1000
commitdd7595a3475407a7fa96a97393bae8c5220e8762 (patch)
treee341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/evas/src/lib/engines/common/evas_draw_main.c
parentAdd the skeleton. (diff)
downloadSledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/evas/src/lib/engines/common/evas_draw_main.c')
-rw-r--r--libraries/evas/src/lib/engines/common/evas_draw_main.c576
1 files changed, 576 insertions, 0 deletions
diff --git a/libraries/evas/src/lib/engines/common/evas_draw_main.c b/libraries/evas/src/lib/engines/common/evas_draw_main.c
new file mode 100644
index 0000000..7652708
--- /dev/null
+++ b/libraries/evas/src/lib/engines/common/evas_draw_main.c
@@ -0,0 +1,576 @@
1#include "evas_common.h"
2#include "evas_convert_main.h"
3#include "evas_private.h"
4
5EAPI Cutout_Rects*
6evas_common_draw_context_cutouts_new(void)
7{
8 Cutout_Rects *rects;
9
10 rects = calloc(1, sizeof(Cutout_Rects));
11 return rects;
12}
13
14EAPI void
15evas_common_draw_context_cutouts_free(Cutout_Rects* rects)
16{
17 rects->active = 0;
18}
19
20EAPI void
21evas_common_draw_context_cutouts_del(Cutout_Rects* rects, int idx)
22{
23 if ((idx >= 0) && (idx < rects->active))
24 {
25 Cutout_Rect *rect;
26
27 rect = rects->rects + idx;
28 memmove(rect, rect + 1,
29 sizeof(Cutout_Rect) * (rects->active - idx - 1));
30 rects->active--;
31 }
32}
33
34void
35evas_common_init(void)
36{
37 evas_common_cpu_init();
38
39 evas_common_blend_init();
40 evas_common_image_init();
41 evas_common_convert_init();
42 evas_common_scale_init();
43 evas_common_rectangle_init();
44 evas_common_polygon_init();
45 evas_common_line_init();
46 evas_common_font_init();
47 evas_common_draw_init();
48 evas_common_tilebuf_init();
49}
50
51void
52evas_common_shutdown(void)
53{
54 evas_font_dir_cache_free();
55 evas_common_image_cache_free();
56}
57
58EAPI void
59evas_common_draw_init(void)
60{
61}
62
63EAPI RGBA_Draw_Context *
64evas_common_draw_context_new(void)
65{
66 RGBA_Draw_Context *dc;
67
68 dc = calloc(1, sizeof(RGBA_Draw_Context));
69 dc->sli.h = 1;
70 return dc;
71}
72
73EAPI void
74evas_common_draw_context_free(RGBA_Draw_Context *dc)
75{
76 if (!dc) return;
77
78 evas_common_draw_context_apply_clean_cutouts(&dc->cutout);
79 free(dc);
80}
81
82EAPI void
83evas_common_draw_context_clear_cutouts(RGBA_Draw_Context *dc)
84{
85 evas_common_draw_context_apply_clean_cutouts(&dc->cutout);
86}
87
88EAPI void
89evas_common_draw_context_font_ext_set(RGBA_Draw_Context *dc,
90 void *data,
91 void *(*gl_new) (void *data, RGBA_Font_Glyph *fg),
92 void (*gl_free) (void *ext_dat),
93 void (*gl_draw) (void *data, void *dest, void *context, RGBA_Font_Glyph *fg, int x, int y))
94{
95 dc->font_ext.data = data;
96 dc->font_ext.func.gl_new = gl_new;
97 dc->font_ext.func.gl_free = gl_free;
98 dc->font_ext.func.gl_draw = gl_draw;
99}
100
101EAPI void
102evas_common_draw_context_clip_clip(RGBA_Draw_Context *dc, int x, int y, int w, int h)
103{
104 if (dc->clip.use)
105 {
106 RECTS_CLIP_TO_RECT(dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h,
107 x, y, w, h);
108 }
109 else
110 evas_common_draw_context_set_clip(dc, x, y, w, h);
111}
112
113EAPI void
114evas_common_draw_context_set_clip(RGBA_Draw_Context *dc, int x, int y, int w, int h)
115{
116 dc->clip.use = 1;
117 dc->clip.x = x;
118 dc->clip.y = y;
119 dc->clip.w = w;
120 dc->clip.h = h;
121}
122
123EAPI void
124evas_common_draw_context_unset_clip(RGBA_Draw_Context *dc)
125{
126 dc->clip.use = 0;
127}
128
129EAPI void
130evas_common_draw_context_set_color(RGBA_Draw_Context *dc, int r, int g, int b, int a)
131{
132 R_VAL(&(dc->col.col)) = (DATA8)r;
133 G_VAL(&(dc->col.col)) = (DATA8)g;
134 B_VAL(&(dc->col.col)) = (DATA8)b;
135 A_VAL(&(dc->col.col)) = (DATA8)a;
136}
137
138EAPI void
139evas_common_draw_context_set_multiplier(RGBA_Draw_Context *dc, int r, int g, int b, int a)
140{
141 dc->mul.use = 1;
142 R_VAL(&(dc->mul.col)) = (DATA8)r;
143 G_VAL(&(dc->mul.col)) = (DATA8)g;
144 B_VAL(&(dc->mul.col)) = (DATA8)b;
145 A_VAL(&(dc->mul.col)) = (DATA8)a;
146}
147
148EAPI void
149evas_common_draw_context_unset_multiplier(RGBA_Draw_Context *dc)
150{
151 dc->mul.use = 0;
152}
153
154EAPI void
155evas_common_draw_context_set_mask(RGBA_Draw_Context *dc, RGBA_Image *mask, int x, int y, int w, int h)
156{
157 dc->mask.mask = mask;
158 dc->mask.x = x;
159 dc->mask.y = y;
160 dc->mask.w = w;
161 dc->mask.h = h;
162}
163
164EAPI void
165evas_common_draw_context_unset_mask(RGBA_Draw_Context *dc)
166{
167 dc->mask.mask = NULL;
168}
169
170
171
172
173
174EAPI void
175evas_common_draw_context_add_cutout(RGBA_Draw_Context *dc, int x, int y, int w, int h)
176{
177// if (dc->cutout.rects > 512) return;
178 if (dc->clip.use)
179 {
180#if 1 // this is a bit faster
181 int xa1, xa2, xb1, xb2;
182
183 xa1 = x;
184 xa2 = xa1 + w - 1;
185 xb1 = dc->clip.x;
186 if (xa2 < xb1) return;
187 xb2 = xb1 + dc->clip.w - 1;
188 if (xa1 >= xb2) return;
189 if (xa2 > xb2) xa2 = xb2;
190 if (xb1 > xa1) xa1 = xb1;
191 x = xa1;
192 w = xa2 - xa1 + 1;
193
194 xa1 = y;
195 xa2 = xa1 + h - 1;
196 xb1 = dc->clip.y;
197 if (xa2 < xb1) return;
198 xb2 = xb1 + dc->clip.h - 1;
199 if (xa1 >= xb2) return;
200 if (xa2 > xb2) xa2 = xb2;
201 if (xb1 > xa1) xa1 = xb1;
202 y = xa1;
203 h = xa2 - xa1 + 1;
204#else
205 RECTS_CLIP_TO_RECT(x, y, w, h,
206 dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h);
207#endif
208 if ((w < 1) || (h < 1)) return;
209 }
210 evas_common_draw_context_cutouts_add(&dc->cutout, x, y, w, h);
211}
212
213int
214evas_common_draw_context_cutout_split(Cutout_Rects* res, int idx, Cutout_Rect *split)
215{
216 /* 1 input rect, multiple out */
217 Cutout_Rect in = res->rects[idx];
218
219 /* this is to save me a LOT of typing */
220#define INX1 (in.x)
221#define INX2 (in.x + in.w)
222#define SPX1 (split->x)
223#define SPX2 (split->x + split->w)
224#define INY1 (in.y)
225#define INY2 (in.y + in.h)
226#define SPY1 (split->y)
227#define SPY2 (split->y + split->h)
228#define X1_IN (in.x < split->x)
229#define X2_IN ((in.x + in.w) > (split->x + split->w))
230#define Y1_IN (in.y < split->y)
231#define Y2_IN ((in.y + in.h) > (split->y + split->h))
232#define R_NEW(_r, _x, _y, _w, _h) { evas_common_draw_context_cutouts_add(_r, _x, _y, _w, _h); }
233 if (!RECTS_INTERSECT(in.x, in.y, in.w, in.h,
234 split->x, split->y, split->w, split->h))
235 {
236 /* No colision => no clipping, don't touch it. */
237 return 1;
238 }
239
240 /* S = split (ie cut out rect) */
241 /* +--+ = in (rect to be cut) */
242
243 /*
244 * +---+
245 * | |
246 * | S |
247 * | |
248 * +---+
249 *
250 */
251 if (X1_IN && X2_IN && Y1_IN && Y2_IN)
252 {
253 R_NEW(res, in.x, in.y, in.w, SPY1 - in.y);
254 R_NEW(res, in.x, SPY1, SPX1 - in.x, SPY2 - SPY1);
255 R_NEW(res, SPX2, SPY1, INX2 - SPX2, SPY2 - SPY1);
256 /* out => (in.x, SPY2, in.w, INY2 - SPY2) */
257 res->rects[idx].h = INY2 - SPY2;
258 res->rects[idx].y = SPY2;
259 return 1;
260 }
261 /* SSSSSSS
262 * S+---+S
263 * S|SSS|S
264 * S|SSS|S
265 * S|SSS|S
266 * S+---+S
267 * SSSSSSS
268 */
269 if (!X1_IN && !X2_IN && !Y1_IN && !Y2_IN)
270 {
271 evas_common_draw_context_cutouts_del(res, idx);
272 return 0;
273 }
274 /* SSS
275 * S+---+
276 * S|S |
277 * S|S |
278 * S|S |
279 * S+---+
280 * SSS
281 */
282 if (!X1_IN && X2_IN && !Y1_IN && !Y2_IN)
283 {
284 /* in => (SPX2, in.y, INX2 - SPX2, in.h) */
285 res->rects[idx].w = INX2 - SPX2;
286 res->rects[idx].x = SPX2;
287 return 1;
288 }
289 /* S
290 * +---+
291 * | S |
292 * | S |
293 * | S |
294 * +---+
295 * S
296 */
297 if (X1_IN && X2_IN && !Y1_IN && !Y2_IN)
298 {
299 R_NEW(res, in.x, in.y, SPX1 - in.x, in.h);
300 /* in => (SPX2, in.y, INX2 - SPX2, in.h) */
301 res->rects[idx].w = INX2 - SPX2;
302 res->rects[idx].x = SPX2;
303 return 1;
304 }
305 /* SSS
306 * +---+S
307 * | S|S
308 * | S|S
309 * | S|S
310 * +---+S
311 * SSS
312 */
313 if (X1_IN && !X2_IN && !Y1_IN && !Y2_IN)
314 {
315 /* in => (in.x, in.y, SPX1 - in.x, in.h) */
316 res->rects[idx].w = SPX1 - in.x;
317 return 1;
318 }
319 /* SSSSSSS
320 * S+---+S
321 * S|SSS|S
322 * | |
323 * | |
324 * +---+
325 *
326 */
327 if (!X1_IN && !X2_IN && !Y1_IN && Y2_IN)
328 {
329 /* in => (in.x, SPY2, in.w, INY2 - SPY2) */
330 res->rects[idx].h = INY2 - SPY2;
331 res->rects[idx].y = SPY2;
332 return 1;
333 }
334 /*
335 * +---+
336 * | |
337 * S|SSS|S
338 * | |
339 * +---+
340 *
341 */
342 if (!X1_IN && !X2_IN && Y1_IN && Y2_IN)
343 {
344 R_NEW(res, in.x, SPY2, in.w, INY2 - SPY2);
345 /* in => (in.x, in.y, in.w, SPY1 - in.y) */
346 res->rects[idx].h = SPY1 - in.y;
347 return 1;
348 }
349 /*
350 * +---+
351 * | |
352 * | |
353 * S|SSS|S
354 * S+---+S
355 * SSSSSSS
356 */
357 if (!X1_IN && !X2_IN && Y1_IN && !Y2_IN)
358 {
359 /* in => (in.x, in.y, in.w, SPY1 - in.y) */
360 res->rects[idx].h = SPY1 - in.y;
361 return 1;
362 }
363 /* SSS
364 * S+---+
365 * S|S |
366 * | |
367 * | |
368 * +---+
369 *
370 */
371 if (!X1_IN && X2_IN && !Y1_IN && Y2_IN)
372 {
373 R_NEW(res, SPX2, in.y, INX2 - SPX2, SPY2 - in.y);
374 /* in => (in.x, SPY2, in.w, INY2 - SPY2) */
375 res->rects[idx].h = INY2 - SPY2;
376 res->rects[idx].y = SPY2;
377 return 1;
378 }
379 /* S
380 * +---+
381 * | S |
382 * | |
383 * | |
384 * +---+
385 *
386 */
387 if (X1_IN && X2_IN && !Y1_IN && Y2_IN)
388 {
389 R_NEW(res, in.x, in.y, SPX1 - in.x, SPY2 - in.y);
390 R_NEW(res, SPX2, in.y, INX2 - SPX2, SPY2 - in.y);
391 /* in => (in.x, SPY2, in.w, INY2 - SPY2) */
392 res->rects[idx].h = INY2 - SPY2;
393 res->rects[idx].y = SPY2;
394 return 1;
395 }
396 /* SSS
397 * +---+S
398 * | S|S
399 * | |
400 * | |
401 * +---+
402 *
403 */
404 if (X1_IN && !X2_IN && !Y1_IN && Y2_IN)
405 {
406 R_NEW(res, in.x, in.y, SPX1 - in.x, SPY2 - in.y);
407 /* in => (in.x, SPY2, in.w, INY2 - SPY2) */
408 res->rects[idx].h = INY2 - SPY2;
409 res->rects[idx].y = SPY2;
410 return 1;
411 }
412 /*
413 * +---+
414 * | |
415 * S|S |
416 * | |
417 * +---+
418 *
419 */
420 if (!X1_IN && X2_IN && Y1_IN && Y2_IN)
421 {
422 R_NEW(res, in.x, SPY2, in.w, INY2 - SPY2);
423 R_NEW(res, SPX2, SPY1, INX2 - SPX2, SPY2 - SPY1);
424 /* in => (in.x, SPY2, in.w, INY2 - SPY2) */
425 res->rects[idx].h = SPY1 - in.y;
426 return 1;
427 }
428 /*
429 * +---+
430 * | |
431 * | S|S
432 * | |
433 * +---+
434 *
435 */
436 if (X1_IN && !X2_IN && Y1_IN && Y2_IN)
437 {
438 R_NEW(res, in.x, SPY2, in.w, INY2 - SPY2);
439 R_NEW(res, in.x, SPY1, SPX1 - in.x, SPY2 - SPY1);
440 /* in => (in.x, in.y, in.w, SPY1 - in.y) */
441 res->rects[idx].h = SPY1 - in.y;
442 return 1;
443 }
444 /*
445 * +---+
446 * | |
447 * | |
448 * S|S |
449 * S+---+
450 * SSS
451 */
452 if (!X1_IN && X2_IN && Y1_IN && !Y2_IN)
453 {
454 R_NEW(res, SPX2, SPY1, INX2 - SPX2, INY2 - SPY1);
455 /* in => (in.x, in.y, in.w, SPY1 - in.y) */
456 res->rects[idx].h = SPY1 - in.y;
457 return 1;
458 }
459 /*
460 * +---+
461 * | |
462 * | |
463 * | S |
464 * +---+
465 * S
466 */
467 if (X1_IN && X2_IN && Y1_IN && !Y2_IN)
468 {
469 R_NEW(res, in.x, SPY1, SPX1 - in.x, INY2 - SPY1);
470 R_NEW(res, SPX2, SPY1, INX2 - SPX2, INY2 - SPY1);
471 /* in => (in.x, in.y, in.w, SPY1 - in.y) */
472 res->rects[idx].h = SPY1 - in.y;
473 return 1;
474 }
475 /*
476 * +---+
477 * | |
478 * | |
479 * | S|S
480 * +---+S
481 * SSS
482 */
483 if (X1_IN && !X2_IN && Y1_IN && !Y2_IN)
484 {
485 R_NEW(res, in.x, SPY1, SPX1 - in.x, INY2 - SPY1);
486 /* in => (in.x, in.y, in.w, SPY1 - in.y) */
487 res->rects[idx].h = SPY1 - in.y;
488 return 1;
489 }
490 evas_common_draw_context_cutouts_del(res, idx);
491 return 0;
492#undef INX1
493#undef INX2
494#undef SPX1
495#undef SPX2
496#undef INY1
497#undef INY2
498#undef SPY1
499#undef SPY2
500#undef X1_IN
501#undef X2_IN
502#undef Y1_IN
503#undef Y2_IN
504#undef R_NEW
505}
506
507EAPI Cutout_Rects*
508evas_common_draw_context_apply_cutouts(RGBA_Draw_Context *dc)
509{
510 Cutout_Rects* res;
511 int i;
512 int j;
513
514 if (!dc->clip.use) return NULL;
515 if ((dc->clip.w <= 0) || (dc->clip.h <= 0)) return NULL;
516
517
518 res = evas_common_draw_context_cutouts_new();
519 evas_common_draw_context_cutouts_add(res, dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h);
520
521 for (i = 0; i < dc->cutout.active; ++i)
522 {
523 /* Don't loop on the element just added to the list as they are already correctly clipped. */
524 int active = res->active;
525
526 for (j = 0; j < active; )
527 {
528 if (evas_common_draw_context_cutout_split(res, j, dc->cutout.rects + i))
529 ++j;
530 else
531 active--;
532 }
533 }
534 return res;
535}
536
537EAPI void
538evas_common_draw_context_apply_clear_cutouts(Cutout_Rects* rects)
539{
540 evas_common_draw_context_apply_clean_cutouts(rects);
541 free(rects);
542}
543
544EAPI void
545evas_common_draw_context_apply_clean_cutouts(Cutout_Rects* rects)
546{
547 free(rects->rects);
548 rects->rects = NULL;
549 rects->active = 0;
550 rects->max = 0;
551}
552
553EAPI void
554evas_common_draw_context_set_anti_alias(RGBA_Draw_Context *dc , unsigned char aa)
555{
556 dc->anti_alias = !!aa;
557}
558
559EAPI void
560evas_common_draw_context_set_color_interpolation(RGBA_Draw_Context *dc, int color_space)
561{
562 dc->interpolation.color_space = color_space;
563}
564
565EAPI void
566evas_common_draw_context_set_render_op(RGBA_Draw_Context *dc , int op)
567{
568 dc->render_op = op;
569}
570
571EAPI void
572evas_common_draw_context_set_sli(RGBA_Draw_Context *dc, int y, int h)
573{
574 dc->sli.y = y;
575 dc->sli.h = h;
576}