summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_draw_main.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2015-09-24 14:06:40 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2015-09-24 14:09:20 +0900
commit217faeebe80db30fe2b2790493505391eeb62f99 (patch)
tree363140dde5338a272ff9555ccc93571e24dc3b70 /src/lib/evas/common/evas_draw_main.c
parent49adf8aa47f37c41ee1fed288c828737104f1c5f (diff)
evas cutouts - optimize to use less cpu
this optimizes draw ctxt cutouts by skipping small ones and remembering the last cutout added so it isn't double-added as well as extending the minimum cutout array to 512 and going up in blocks of 512 instead of 128. also optimize the clipping code a bit more.
Diffstat (limited to 'src/lib/evas/common/evas_draw_main.c')
-rw-r--r--src/lib/evas/common/evas_draw_main.c87
1 files changed, 52 insertions, 35 deletions
diff --git a/src/lib/evas/common/evas_draw_main.c b/src/lib/evas/common/evas_draw_main.c
index 53d57dd66b..3a62d94c08 100644
--- a/src/lib/evas/common/evas_draw_main.c
+++ b/src/lib/evas/common/evas_draw_main.c
@@ -2,7 +2,7 @@
2#include "evas_convert_main.h" 2#include "evas_convert_main.h"
3#include "evas_private.h" 3#include "evas_private.h"
4 4
5EAPI Cutout_Rects* 5EAPI Cutout_Rects *
6evas_common_draw_context_cutouts_new(void) 6evas_common_draw_context_cutouts_new(void)
7{ 7{
8 Cutout_Rects *rects; 8 Cutout_Rects *rects;
@@ -17,6 +17,7 @@ evas_common_draw_context_cutouts_dup(Cutout_Rects *rects2, const Cutout_Rects *r
17 if (!rects) return; 17 if (!rects) return;
18 rects2->active = rects->active; 18 rects2->active = rects->active;
19 rects2->max = rects->max; 19 rects2->max = rects->max;
20 rects2->last_add = rects->last_add;
20 if (rects->max > 0) 21 if (rects->max > 0)
21 { 22 {
22 const size_t sz = sizeof(Cutout_Rect) * rects->max; 23 const size_t sz = sizeof(Cutout_Rect) * rects->max;
@@ -30,6 +31,7 @@ evas_common_draw_context_cutouts_free(Cutout_Rects* rects)
30{ 31{
31 if (!rects) return; 32 if (!rects) return;
32 rects->active = 0; 33 rects->active = 0;
34 rects->last_add.w = 0;
33} 35}
34 36
35EAPI void 37EAPI void
@@ -39,10 +41,11 @@ evas_common_draw_context_cutouts_del(Cutout_Rects* rects, int idx)
39 { 41 {
40 Cutout_Rect *rect; 42 Cutout_Rect *rect;
41 43
42 rect = rects->rects + idx; 44 rect = rects->rects + idx;
43 memmove(rect, rect + 1, 45 memmove(rect, rect + 1,
44 sizeof(Cutout_Rect) * (rects->active - idx - 1)); 46 sizeof(Cutout_Rect) * (rects->active - idx - 1));
45 rects->active--; 47 rects->active--;
48 rects->last_add.w = 0;
46 } 49 }
47} 50}
48 51
@@ -228,40 +231,53 @@ evas_common_draw_context_add_cutout(RGBA_Draw_Context *dc, int x, int y, int w,
228 if (dc->clip.use) 231 if (dc->clip.use)
229 { 232 {
230#if 1 // this is a bit faster 233#if 1 // this is a bit faster
231 int xa1, xa2, xb1, xb2; 234 int x1, x2, y1, y2;
232 235 int cx1, cx2, cy1, cy2;
233 xa1 = x; 236
234 xa2 = xa1 + w - 1; 237 x2 = x + w;
235 xb1 = dc->clip.x; 238 cx1 = dc->clip.x;
236 if (xa2 < xb1) return; 239 if (x2 <= cx1) return;
237 xb2 = xb1 + dc->clip.w - 1; 240 x1 = x;
238 if (xa1 >= xb2) return; 241 cx2 = cx1 + dc->clip.w;
239 if (xa2 > xb2) xa2 = xb2; 242 if (x1 >= cx2) return;
240 if (xb1 > xa1) xa1 = xb1; 243
241 x = xa1; 244 if (x1 < cx1) x1 = cx1;
242 w = xa2 - xa1 + 1; 245 if (x2 > cx2) x2 = cx2;
243 246
244 xa1 = y; 247 y2 = y + h;
245 xa2 = xa1 + h - 1; 248 cy1 = dc->clip.y;
246 xb1 = dc->clip.y; 249 if (y2 <= cy1) return;
247 if (xa2 < xb1) return; 250 y1 = y;
248 xb2 = xb1 + dc->clip.h - 1; 251 cy2 = cy1 + dc->clip.h;
249 if (xa1 >= xb2) return; 252 if (y1 >= cy2) return;
250 if (xa2 > xb2) xa2 = xb2; 253
251 if (xb1 > xa1) xa1 = xb1; 254 if (y1 < cy1) y1 = cy1;
252 y = xa1; 255 if (y2 > cy2) y2 = cy2;
253 h = xa2 - xa1 + 1; 256
257 x = x1;
258 y = y1;
259 w = x2 - x1;
260 h = y2 - y1;
254#else 261#else
255 RECTS_CLIP_TO_RECT(x, y, w, h, 262 RECTS_CLIP_TO_RECT(x, y, w, h,
256 dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h); 263 dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h);
257#endif 264#endif
258 if ((w < 1) || (h < 1)) return;
259 } 265 }
266 if ((w * h) <= (8 * 8)) return;
267 if (dc->cutout.last_add.w > 0)
268 {
269 if ((dc->cutout.last_add.x == x) && (dc->cutout.last_add.y == y) &&
270 (dc->cutout.last_add.w == w) && (dc->cutout.last_add.h == h)) return;
271 }
272 dc->cutout.last_add.x = x;
273 dc->cutout.last_add.y = y;
274 dc->cutout.last_add.w = w;
275 dc->cutout.last_add.h = h;
260 evas_common_draw_context_cutouts_add(&dc->cutout, x, y, w, h); 276 evas_common_draw_context_cutouts_add(&dc->cutout, x, y, w, h);
261} 277}
262 278
263int 279static int
264evas_common_draw_context_cutout_split(Cutout_Rects* res, int idx, Cutout_Rect *split) 280evas_common_draw_context_cutout_split(Cutout_Rects *res, int idx, Cutout_Rect *split)
265{ 281{
266 /* 1 input rect, multiple out */ 282 /* 1 input rect, multiple out */
267 Cutout_Rect in = res->rects[idx]; 283 Cutout_Rect in = res->rects[idx];
@@ -554,10 +570,10 @@ evas_common_draw_context_cutout_split(Cutout_Rects* res, int idx, Cutout_Rect *s
554#undef R_NEW 570#undef R_NEW
555} 571}
556 572
557EAPI Cutout_Rects* 573EAPI Cutout_Rects *
558evas_common_draw_context_apply_cutouts(RGBA_Draw_Context *dc, Cutout_Rects *reuse) 574evas_common_draw_context_apply_cutouts(RGBA_Draw_Context *dc, Cutout_Rects *reuse)
559{ 575{
560 Cutout_Rects* res = NULL; 576 Cutout_Rects *res = NULL;
561 int i; 577 int i;
562 int j; 578 int j;
563 579
@@ -595,7 +611,7 @@ evas_common_draw_context_apply_cutouts(RGBA_Draw_Context *dc, Cutout_Rects *reus
595 if (res->active > 1) 611 if (res->active > 1)
596 { 612 {
597 int found = 1; 613 int found = 1;
598 614
599 while (found) 615 while (found)
600 { 616 {
601 found = 0; 617 found = 0;
@@ -659,19 +675,20 @@ evas_common_draw_context_apply_cutouts(RGBA_Draw_Context *dc, Cutout_Rects *reus
659} 675}
660 676
661EAPI void 677EAPI void
662evas_common_draw_context_apply_clear_cutouts(Cutout_Rects* rects) 678evas_common_draw_context_apply_clear_cutouts(Cutout_Rects *rects)
663{ 679{
664 evas_common_draw_context_apply_clean_cutouts(rects); 680 evas_common_draw_context_apply_clean_cutouts(rects);
665 free(rects); 681 free(rects);
666} 682}
667 683
668EAPI void 684EAPI void
669evas_common_draw_context_apply_clean_cutouts(Cutout_Rects* rects) 685evas_common_draw_context_apply_clean_cutouts(Cutout_Rects *rects)
670{ 686{
671 free(rects->rects); 687 free(rects->rects);
672 rects->rects = NULL; 688 rects->rects = NULL;
673 rects->active = 0; 689 rects->active = 0;
674 rects->max = 0; 690 rects->max = 0;
691 rects->last_add.w = 0;
675} 692}
676 693
677EAPI void 694EAPI void