Evas filters: Prevent buffer creation when running filter
authorJean-Philippe Andre <jp.andre@samsung.com>
Fri, 7 Feb 2014 02:22:36 +0000 (11:22 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Fri, 7 Feb 2014 08:33:18 +0000 (17:33 +0900)
In async mode, the filter runs in the render thread, so can't
allocate buffers on the fly.
This case should not happen, unless maybe a source has a null
size (eg. it's invisible and not properly rendered).

src/lib/evas/filters/evas_filter.c
src/lib/evas/filters/evas_filter_private.h

index 0c8a6a3..215f88f 100644 (file)
@@ -347,68 +347,6 @@ _rgba_image_alloc(Evas_Filter_Buffer const *fb, void *data)
    return image;
 }
 
-/*
-Eina_Bool
-evas_filter_buffer_alloc(Evas_Filter_Buffer *fb, int w, int h)
-{
-   if (!fb) return EINA_FALSE;
-   INF("Allocate buffer %d: backing %p", fb->id, fb->backing);
-   if (fb->backing)
-     {
-        RGBA_Image *im;
-        int W, H;
-
-        if (fb->ctx->gl_engine)
-          {
-             // This needs to be counter-checked.
-             INF("Nope, gl engine is used");
-             return EINA_TRUE;
-          }
-
-        im = fb->backing;
-        if (!im->image.data)
-          {
-             if (fb->allocated)
-               fb->ENFN->image_free(fb->ENDT, im);
-             fb->allocated = EINA_FALSE;
-             fb->backing = NULL;
-          }
-        else
-          {
-             fb->ENFN->image_size_get(fb->ENDT, fb->backing, &W, &H);
-             if ((W == w) && (H == h))
-               {
-                  INF("Nope, already fine");
-                  return EINA_TRUE;
-               }
-
-             if (!fb->transient)
-               ERR("Buffer dimensions mismatch with external image!");
-             _filter_buffer_backing_free(fb);
-          }
-     }
-   if ((fb->w && (fb->w != w)) || (fb->h && (fb->h != h)))
-     {
-        ERR("Buffer dimensions mismatch!");
-        //return EINA_FALSE;
-     }
-   if (fb->allocated && fb->backing)
-     {
-        RGBA_Image *a = fb->backing;
-        INF("Already allocated. Is that true? backing %p and data %p", a, a?a->image.data:NULL);
-        return EINA_TRUE;
-     }
-   fb->w = w;
-   fb->h = h;
-
-   fb->backing = _rgba_image_alloc(fb, NULL);
-   fb->allocated = (fb->backing != NULL);
-   RGBA_Image *a = fb->backing;
-   INF("Allocated buf %d with backing %p data %p", fb->id, fb->backing, a?a->image.data:0);
-   return fb->allocated;
-}
-*/
-
 Eina_Bool
 evas_filter_context_buffers_allocate_all(Evas_Filter_Context *ctx,
                                          unsigned w, unsigned h)
@@ -516,7 +454,7 @@ evas_filter_context_buffers_allocate_all(Evas_Filter_Context *ctx,
              continue;
           }
 
-        //DBG("Allocating buffer of size %ux%u", fb->w, fb->h);
+        //DBG("Allocating buffer of size %ux%u alpha %d", fb->w, fb->h, fb->alpha_only);
         ie = (Image_Entry *) _rgba_image_alloc(fb, NULL);
         if (!ie)
           {
@@ -787,6 +725,12 @@ evas_filter_temporary_buffer_get(Evas_Filter_Context *ctx, int w, int h,
           }
      }
 
+   if (ctx->running && ctx->async)
+     {
+        ERR("Can not create a new buffer from this thread!");
+        return NULL;
+     }
+
    buf = _buffer_new(ctx, w, h, alpha_only);
    buf->locked = EINA_TRUE;
    INF("Created temporary buffer: %d", buf->id);
@@ -1661,19 +1605,23 @@ _filter_chain_run(Evas_Filter_Context *ctx)
    Evas_Filter_Command *cmd;
    Eina_Bool ok = EINA_TRUE;
 
+   ctx->running = EINA_TRUE;
    EINA_INLIST_FOREACH(ctx->commands, cmd)
      {
         ok = _filter_command_run(cmd);
         if (!ok)
           {
              ERR("Filter processing failed!");
-             return EINA_FALSE;
+             goto end;
           }
      }
 
-   if (!ok) return EINA_FALSE;
+   if (!ok) goto end;
+   ok = _filter_target_render(ctx);
 
-   return _filter_target_render(ctx);
+end:
+   ctx->running = EINA_FALSE;
+   return ok;
 }
 
 static void
index eeacd42..544d767 100644 (file)
@@ -66,6 +66,7 @@ struct _Evas_Filter_Context
 
    Eina_Bool async : 1;
    Eina_Bool gl_engine : 1;
+   Eina_Bool running : 1;
 };
 
 struct _Evas_Filter_Command