evas sw render: fix previous thread fix to be portable
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Fri, 1 Apr 2016 02:29:50 +0000 (11:29 +0900)
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>
Fri, 1 Apr 2016 02:29:50 +0000 (11:29 +0900)
this fixes the fix 4d6a8a7fce51b5654404226668a27d52d1e30eb3 to be
portable to platfomrs that do not support __thread - seemingly openbsd
does not (argh!) and maybe others. so on these platforms then they
dont get the optimization of keeping a cutout rect pool to avoid
re-allocation.

this also every 4096 draws "resets" the cutout cache so it doesnt
expand and stay expanded forever.

@fix

src/lib/evas/common/evas_font_draw.c
src/lib/evas/common/evas_map_image.c
src/lib/evas/common/evas_rectangle_main.c
src/lib/evas/common/evas_scale_main.c

index bf5141b..c61e921 100644 (file)
@@ -348,7 +348,12 @@ error:
 EAPI Eina_Bool
 evas_common_font_draw_cb(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int y, Evas_Glyph_Array *glyphs, Evas_Common_Font_Draw_Cb cb)
 {
+#ifdef HAVE_THREAD_SPECIFIER
+   static __thread int rects_used = 0;
    static __thread Cutout_Rects *rects = NULL;
+#else
+   Cutout_Rects *rects = NULL;
+#endif
    int ext_x, ext_y, ext_w, ext_h;
    int im_w, im_h;
    RGBA_Gfx_Func func;
@@ -412,6 +417,16 @@ evas_common_font_draw_cb(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int y, E
                             func, r->x, r->y, r->w, r->h,
                             im_w, im_h);
                }
+#ifdef HAVE_THREAD_SPECIFIER
+             rects_used++;
+             if (rects_used >= 4096)
+               {
+                  evas_common_draw_context_cutouts_free(rects);
+                  rects = NULL;
+               }
+#else
+             evas_common_draw_context_cutouts_free(rects);
+#endif
           }
         dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
 
index eb94ada..f5b1a32 100644 (file)
@@ -745,7 +745,12 @@ evas_common_map_rgba_cb(RGBA_Image *src, RGBA_Image *dst,
                         int smooth, int level,
                         Evas_Common_Map_RGBA_Cb cb)
 {
+#ifdef HAVE_THREAD_SPECIFIER
+   static __thread int rects_used = 0;
    static __thread Cutout_Rects *rects = NULL;
+#else
+   Cutout_Rects *rects = NULL;
+#endif
    Cutout_Rect  *r;
    int          c, cx, cy, cw, ch;
    int          i;
@@ -784,6 +789,16 @@ evas_common_map_rgba_cb(RGBA_Image *src, RGBA_Image *dst,
         evas_common_draw_context_set_clip(dc, r->x, r->y, r->w, r->h);
         cb(src, dst, dc, p, smooth, level);
      }
+#ifdef HAVE_THREAD_SPECIFIER
+   rects_used++;
+   if (rects_used >= 4096)
+     {
+        evas_common_draw_context_cutouts_free(rects);
+        rects = NULL;
+     }
+#else
+   evas_common_draw_context_cutouts_free(rects);
+#endif
    /* restore clip info */
    dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
 }
@@ -791,7 +806,12 @@ evas_common_map_rgba_cb(RGBA_Image *src, RGBA_Image *dst,
 EAPI Eina_Bool
 evas_common_map_thread_rgba_cb(RGBA_Image *src, RGBA_Image *dst, RGBA_Draw_Context *dc, RGBA_Map *map, int smooth, int level, int offset, Evas_Common_Map_Thread_RGBA_Cb cb)
 {
+#ifdef HAVE_THREAD_SPECIFIER
+   static __thread int rects_used = 0;
    static __thread Cutout_Rects *rects = NULL;
+#else
+   Cutout_Rects *rects = NULL;
+#endif
    Cutout_Rect  *r;
    int          c, cx, cy, cw, ch;
    int          i;
@@ -833,7 +853,16 @@ evas_common_map_thread_rgba_cb(RGBA_Image *src, RGBA_Image *dst, RGBA_Draw_Conte
         evas_common_draw_context_set_clip(dc, r->x, r->y, r->w, r->h);
         ret |= cb(src, dst, dc, map, smooth, level, offset);
      }
-
+#ifdef HAVE_THREAD_SPECIFIER
+   rects_used++;
+   if (rects_used >= 4096)
+     {
+        evas_common_draw_context_cutouts_free(rects);
+        rects = NULL;
+     }
+#else
+   evas_common_draw_context_cutouts_free(rects);
+#endif
    /* restore clip info */
    dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
 
index bd4649b..388fba6 100644 (file)
@@ -12,7 +12,12 @@ evas_common_rectangle_init(void)
 EAPI void
 evas_common_rectangle_draw_cb(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int y, int w, int h, Evas_Common_Rectangle_Draw_Cb cb)
 {
+#ifdef HAVE_THREAD_SPECIFIER
+   static __thread int rects_used = 0;
    static __thread Cutout_Rects *rects = NULL;
+#else
+   Cutout_Rects *rects = NULL;
+#endif
    Cutout_Rect  *r;
    int          c, cx, cy, cw, ch;
    int          i;
@@ -27,22 +32,32 @@ evas_common_rectangle_draw_cb(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int
    /* no cutouts - cut right to the chase */
    if (!dc->cutout.rects)
      {
-       cb(dst, dc, x, y, w, h);
+        cb(dst, dc, x, y, w, h);
      }
    else
      {
-       evas_common_draw_context_clip_clip(dc, x, y, w, h);
-       /* our clip is 0 size.. abort */
-       if ((dc->clip.w > 0) && (dc->clip.h > 0))
-         {
+        evas_common_draw_context_clip_clip(dc, x, y, w, h);
+        /* our clip is 0 size.. abort */
+        if ((dc->clip.w > 0) && (dc->clip.h > 0))
+          {
              rects = evas_common_draw_context_apply_cutouts(dc, rects);
-            for (i = 0; i < rects->active; ++i)
-              {
-                 r = rects->rects + i;
-                 evas_common_draw_context_set_clip(dc, r->x, r->y, r->w, r->h);
-                 cb(dst, dc, x, y, w, h);
-              }
-         }
+             for (i = 0; i < rects->active; ++i)
+               {
+                  r = rects->rects + i;
+                  evas_common_draw_context_set_clip(dc, r->x, r->y, r->w, r->h);
+                  cb(dst, dc, x, y, w, h);
+               }
+#ifdef HAVE_THREAD_SPECIFIER
+             rects_used++;
+             if (rects_used >= 4096)
+               {
+                  evas_common_draw_context_cutouts_free(rects);
+                  rects = NULL;
+               }
+#else
+             evas_common_draw_context_cutouts_free(rects);
+#endif
+          }
      }
    /* restore clip info */
    dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
index bd30a47..6c8a262 100644 (file)
@@ -40,7 +40,12 @@ evas_common_scale_rgba_in_to_out_clip_cb(RGBA_Image *src, RGBA_Image *dst,
                                          int dst_region_w, int dst_region_h,
                                          Evas_Common_Scale_In_To_Out_Clip_Cb cb)
 {
+#ifdef HAVE_THREAD_SPECIFIER
+   static __thread int rects_used = 0;
    static __thread Cutout_Rects *rects = NULL;
+#else
+   Cutout_Rects *rects = NULL;
+#endif
    Cutout_Rect  *r;
    int          c, cx, cy, cw, ch;
    int          i;
@@ -67,20 +72,29 @@ evas_common_scale_rgba_in_to_out_clip_cb(RGBA_Image *src, RGBA_Image *dst,
    /* our clip is 0 size.. abort */
    if ((dc->clip.w <= 0) || (dc->clip.h <= 0))
      {
-       dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
-       return EINA_FALSE;
+        dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
+        return EINA_FALSE;
      }
 
    rects = evas_common_draw_context_apply_cutouts(dc, rects);
    for (i = 0; i < rects->active; ++i)
      {
-       r = rects->rects + i;
-       evas_common_draw_context_set_clip(dc, r->x, r->y, r->w, r->h);
+        r = rects->rects + i;
+        evas_common_draw_context_set_clip(dc, r->x, r->y, r->w, r->h);
         ret |= cb(src, dst, dc,
                   src_region_x, src_region_y, src_region_w, src_region_h,
                   dst_region_x, dst_region_y, dst_region_w, dst_region_h);
      }
-
+#ifdef HAVE_THREAD_SPECIFIER
+   rects_used++;
+   if (rects_used >= 4096)
+     {
+        evas_common_draw_context_cutouts_free(rects);
+        rects = NULL;
+     }
+#else
+   evas_common_draw_context_cutouts_free(rects);
+#endif
    /* restore clip info */
    dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;