e_plane: added e_plane_hook
authorChangyeon Lee <cyeon.lee@samsung.com>
Tue, 20 Jun 2017 05:42:27 +0000 (14:42 +0900)
committerBoram Park <boram1288.park@samsung.com>
Wed, 5 Jul 2017 03:02:43 +0000 (12:02 +0900)
Change-Id: I009920b5631f04aba38e2f0d1a4a443b25ba8935

src/bin/e_plane.c
src/bin/e_plane.h

index c242271bf18b73e0a41cbba5d66d865ac2a00abc..d550113ebd91c60e117705241cdf3beaee2f87b7 100644 (file)
@@ -26,6 +26,45 @@ static Eina_Bool plane_trace_debug = 0;
 
 E_API int E_EVENT_PLANE_WIN_CHANGE = -1;
 
+static int _e_plane_hooks_delete = 0;
+static int _e_plane_hooks_walking = 0;
+
+static Eina_Inlist *_e_plane_hooks[] =
+{
+   [E_PLANE_HOOK_VIDEO_SET] = NULL,
+};
+
+static void
+_e_plane_hooks_clean(void)
+{
+   Eina_Inlist *l;
+   E_Plane_Hook *ch;
+   unsigned int x;
+   for (x = 0; x < E_PLANE_HOOK_LAST; x++)
+     EINA_INLIST_FOREACH_SAFE(_e_plane_hooks[x], l, ch)
+       {
+          if (!ch->delete_me) continue;
+          _e_plane_hooks[x] = eina_inlist_remove(_e_plane_hooks[x], EINA_INLIST_GET(ch));
+         free(ch);
+       }
+}
+
+static void
+_e_plane_hook_call(E_Plane_Hook_Point hookpoint, E_Plane *plane)
+{
+   E_Plane_Hook *ch;
+
+   _e_plane_hooks_walking++;
+   EINA_INLIST_FOREACH(_e_plane_hooks[hookpoint], ch)
+     {
+        if (ch->delete_me) continue;
+        ch->func(ch->data, plane);
+     }
+   _e_plane_hooks_walking--;
+   if ((_e_plane_hooks_walking == 0) && (_e_plane_hooks_delete > 0))
+     _e_plane_hooks_clean();
+}
+
 static E_Comp_Wl_Buffer *
 _get_comp_wl_buffer(E_Client *ec)
 {
@@ -559,6 +598,34 @@ _e_plane_unset_candidate_set(E_Plane *plane)
    plane->unset_candidate = EINA_TRUE;
 }
 
+E_API E_Plane_Hook *
+e_plane_hook_add(E_Plane_Hook_Point hookpoint, E_Plane_Hook_Cb func, const void *data)
+{
+   E_Plane_Hook *ch;
+
+   EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_PLANE_HOOK_LAST, NULL);
+   ch = E_NEW(E_Plane_Hook, 1);
+   if (!ch) return NULL;
+   ch->hookpoint = hookpoint;
+   ch->func = func;
+   ch->data = (void*)data;
+   _e_plane_hooks[hookpoint] = eina_inlist_append(_e_plane_hooks[hookpoint], EINA_INLIST_GET(ch));
+   return ch;
+}
+
+E_API void
+e_plane_hook_del(E_Plane_Hook *ch)
+{
+   ch->delete_me = 1;
+   if (_e_plane_hooks_walking == 0)
+     {
+        _e_plane_hooks[ch->hookpoint] = eina_inlist_remove(_e_plane_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
+        free(ch);
+     }
+   else
+     _e_plane_hooks_delete++;
+}
+
 EINTERN Eina_Bool
 e_plane_init(void)
 {
index 47d0497dc7bb842f5cc97b83d67bc283e2970a85..b03f88bd4b51a8dc747db423a75a3b66bacd4b2b 100644 (file)
@@ -26,6 +26,9 @@ typedef enum _E_Plane_Color
 typedef struct _E_Plane                      E_Plane;
 typedef struct _E_Plane_Commit_Data          E_Plane_Commit_Data;
 typedef struct _E_Event_Plane_Win_Change     E_Event_Plane_Win_Change;
+typedef struct _E_Plane_Hook                 E_Plane_Hook;
+typedef void (*E_Plane_Hook_Cb) (void *data, E_Plane *plane);
+
 #else
 #ifndef E_PLANE_H
 #define E_PLANE_H
@@ -96,6 +99,21 @@ struct _E_Plane_Commit_Data {
    E_Comp_Wl_Buffer_Ref  buffer_ref;
 };
 
+typedef enum _E_Plane_Hook_Point
+{
+   E_PLANE_HOOK_VIDEO_SET,
+   E_PLANE_HOOK_LAST
+} E_Plane_Hook_Point;
+
+struct _E_Plane_Hook
+{
+   EINA_INLIST;
+   E_Plane_Hook_Point hookpoint;
+   E_Plane_Hook_Cb func;
+   void *data;
+   unsigned char delete_me : 1;
+};
+
 struct _E_Event_Plane_Win_Change
 {
    E_Plane *ep;
@@ -138,5 +156,8 @@ E_API Eina_Bool              e_plane_is_cursor(E_Plane *plane);
 E_API E_Plane_Color          e_plane_color_val_get(E_Plane *plane);
 E_API Eina_Bool              e_plane_is_fb_target(E_Plane *plane);
 
+E_API E_Plane_Hook          *e_plane_hook_add(E_Plane_Hook_Point hookpoint, E_Plane_Hook_Cb func, const void *data);
+E_API void                   e_plane_hook_del(E_Plane_Hook *ch);
+
 #endif
 #endif