subsurface: Add a function for getting parent of sub-surface 73/260273/1
authorSeunghun Lee <shiin.lee@samsung.com>
Wed, 23 Jun 2021 01:53:24 +0000 (10:53 +0900)
committerSeunghun Lee <shiin.lee@samsung.com>
Wed, 23 Jun 2021 04:50:17 +0000 (13:50 +0900)
To get a parent of sub-surface without accessing particular sub-surface
data, this adds e_comp_wl_subsurface_panret_get() function. This should
also help with readability.

As the name implies, this should be called with a E_Client associated
with sub-surface instance, but it will be okay to be called with
not sub-surface instance. In that case, it will just return NULL.

Change-Id: I08f340424b46fdb54141fa41747ba55ad2ae6875

13 files changed:
src/bin/e_client.c
src/bin/e_comp_wl.c
src/bin/e_comp_wl_rsm.c
src/bin/e_comp_wl_subsurface.c
src/bin/e_comp_wl_subsurface.h
src/bin/e_comp_wl_viewport.c
src/bin/e_eom.c
src/bin/e_hwc_window.c
src/bin/e_info_server.c
src/bin/e_policy_wl.c
src/bin/e_process.c
src/bin/video/e_client_video.c
src/bin/video/iface/e_video_hwc.c

index 8a87e08..79ec5a9 100644 (file)
@@ -3838,31 +3838,24 @@ _e_client_transform_core_check_change(E_Client *ec)
      }
 
    // check parent matrix change
-   if (cdata)
+   E_Client *parent = e_comp_wl_subsurface_parent_get(ec);
+   if (parent && parent->transform_core.result.enable)
      {
-        if (cdata->sub.data)
-          {
-             E_Client *parent = cdata->sub.data->parent;
-
-             if (parent && parent->transform_core.result.enable)
-               {
-                  ec->transform_core.parent.enable = EINA_TRUE;
+        ec->transform_core.parent.enable = EINA_TRUE;
 
-                  if (!e_util_transform_matrix_equal_check(&ec->transform_core.parent.matrix,
-                                                           &parent->transform_core.result.matrix))
-                    {
-                       check = EINA_TRUE;
-                       ec->transform_core.parent.matrix = parent->transform_core.result.matrix;
-                    }
-               }
-             else if (ec->transform_core.parent.enable)
-               {
-                  ec->transform_core.parent.enable = EINA_FALSE;
-                  e_util_transform_matrix_load_identity(&ec->transform_core.parent.matrix);
-                  check = EINA_TRUE;
-               }
+        if (!e_util_transform_matrix_equal_check(&ec->transform_core.parent.matrix,
+                                                 &parent->transform_core.result.matrix))
+          {
+             check = EINA_TRUE;
+             ec->transform_core.parent.matrix = parent->transform_core.result.matrix;
           }
      }
+   else if (ec->transform_core.parent.enable)
+     {
+        ec->transform_core.parent.enable = EINA_FALSE;
+        e_util_transform_matrix_load_identity(&ec->transform_core.parent.matrix);
+        check = EINA_TRUE;
+     }
 
    return check;
 }
index a34ab8b..4cd98a2 100644 (file)
@@ -396,18 +396,15 @@ e_comp_wl_map_size_cal_from_viewport(E_Client *ec)
 E_API E_Client*
 e_comp_wl_topmost_parent_get(E_Client *ec)
 {
-   E_Client *parent = NULL;
+   E_Client *parent;
 
-   if (!ec->comp_data || !ec->comp_data->sub.data)
-      return ec;
-
-   parent = ec->comp_data->sub.data->parent;
+   parent = e_comp_wl_subsurface_parent_get(ec);
    while (parent)
      {
-        if (!parent->comp_data || !parent->comp_data->sub.data)
+        if (!e_comp_wl_subsurface_check(parent))
           return parent;
 
-        parent = parent->comp_data->sub.data->parent;
+        parent = e_comp_wl_subsurface_parent_get(parent);
      }
 
    return ec;
index 2ff17d9..6ce95a9 100644 (file)
@@ -3227,8 +3227,8 @@ e_comp_wl_remote_surface_commit(E_Client *ec)
 {
    E_Comp_Wl_Remote_Provider *provider;
    E_Comp_Wl_Remote_Source *source = NULL;
-   E_Comp_Wl_Subsurf_Data *sdata, *ssdata;
-   E_Client *offscreen_parent;
+   E_Comp_Wl_Subsurf_Data *sdata;
+   E_Client *parent, *offscreen_parent;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
    EINA_SAFETY_ON_TRUE_RETURN_VAL(e_object_is_del(E_OBJECT(ec)), EINA_FALSE);
@@ -3251,25 +3251,26 @@ e_comp_wl_remote_surface_commit(E_Client *ec)
      }
 
    /* subsurface case */
-   if ((sdata = ec->comp_data->sub.data))
+   if (e_comp_wl_subsurface_check(ec))
      {
         /* check for valid subcompositor data */
-        if (!sdata->parent)
+        parent = e_comp_wl_subsurface_parent_get(ec);
+        if (!parent)
           return EINA_FALSE;
 
-        if (!sdata->parent->comp_data)
+        if (!parent->comp_data)
           return EINA_FALSE;
 
-        if (e_object_is_del(E_OBJECT(sdata->parent)))
+        if (e_object_is_del(E_OBJECT(parent)))
           return EINA_FALSE;
 
-        if (!(ssdata = sdata->parent->comp_data->sub.data))
+        if (!(sdata = parent->comp_data->sub.data))
           return EINA_FALSE;
 
-        if (!ssdata->remote_surface.offscreen_parent)
+        if (!sdata->remote_surface.offscreen_parent)
           return EINA_FALSE;
 
-        offscreen_parent = ssdata->remote_surface.offscreen_parent;
+        offscreen_parent = sdata->remote_surface.offscreen_parent;
 
         provider = _remote_provider_find(offscreen_parent);
         if (!provider) return EINA_FALSE;
index 770279e..0e4dde2 100644 (file)
@@ -1338,6 +1338,15 @@ e_comp_wl_subsurface_check(E_Client *ec)
    return ec->comp_data ? !!ec->comp_data->sub.data : EINA_FALSE;
 }
 
+EINTERN E_Client *
+e_comp_wl_subsurface_parent_get(E_Client *ec)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
+   /* Must be called with valid comp_data. */
+   EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, NULL);
+   return ec->comp_data->sub.data ? ec->comp_data->sub.data->parent : NULL;
+}
+
 static void
 _e_comp_wl_subsurface_cb_dummy_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
 {
index 18d1c4d..d0b5056 100644 (file)
@@ -24,5 +24,6 @@ EINTERN Eina_Bool     e_comp_wl_video_subsurface_has(E_Client *ec);
 EINTERN Eina_Bool     e_comp_wl_normal_subsurface_has(E_Client *ec);
 EINTERN void          e_comp_wl_subsurface_check_below_bg_rectangle(E_Client *ec);
 EINTERN Eina_Bool     e_comp_wl_subsurface_check(E_Client *ec);
+EINTERN E_Client     *e_comp_wl_subsurface_parent_get(E_Client *ec);
 
 #endif
index 645c199..2c28f42 100644 (file)
@@ -107,18 +107,15 @@ static void _e_comp_wl_viewport_parent_check(E_Viewport *viewport);
 static E_Client*
 _topmost_parent_get(E_Client *ec)
 {
-   E_Client *parent = NULL;
+   E_Client *parent;
 
-   if (!ec->comp_data || !ec->comp_data->sub.data)
-     return ec;
-
-   parent = ec->comp_data->sub.data->parent;
+   parent = e_comp_wl_subsurface_parent_get(ec);
    while (parent)
      {
-        if (!parent->comp_data || !parent->comp_data->sub.data)
+        if (!e_comp_wl_subsurface_check(parent))
           return parent;
 
-        parent = parent->comp_data->sub.data->parent;
+        parent = e_comp_wl_subsurface_parent_get(parent);
      }
 
    return ec;
@@ -251,7 +248,7 @@ _e_comp_wl_viewport_parent_check(E_Viewport *viewport)
 
    if (e_object_is_del(E_OBJECT(ec)) || !ec->comp_data) return;
 
-   new_parent = (ec->comp_data->sub.data) ? ec->comp_data->sub.data->parent : NULL;
+   new_parent = e_comp_wl_subsurface_parent_get(ec);
 
    if (viewport->epc == new_parent) return;
 
index ca857c7..97ab361 100644 (file)
@@ -353,7 +353,6 @@ _e_eom_output_by_ec_child_get(E_Client *ec)
 {
    E_EomOutputPtr eom_output = NULL;
    E_Client *parent_ec = NULL, *output_ec = NULL;
-   E_Comp_Wl_Client_Data *cdata = NULL, *parent_cdata = NULL;
    Eina_List *l;
 
    EINA_LIST_FOREACH(g_eom->eom_outputs, l, eom_output)
@@ -363,19 +362,13 @@ _e_eom_output_by_ec_child_get(E_Client *ec)
 
         if (output_ec == ec) return eom_output;
 
-        cdata = e_client_cdata_get(ec);
-        if (!cdata) continue;
-        if (!cdata->sub.data) continue;
-
-        parent_ec = cdata->sub.data->parent;
+        parent_ec = e_comp_wl_subsurface_parent_get(ec);
         while (parent_ec)
           {
              if (parent_ec == output_ec) return eom_output;
-             parent_cdata = e_client_cdata_get(parent_ec);
-             if (!parent_cdata) break;
-             if (!parent_cdata->sub.data) break;
+             if (!e_comp_wl_subsurface_check(parent_ec)) break;
 
-             parent_ec = parent_cdata->sub.data->parent;
+             parent_ec = e_comp_wl_subsurface_parent_get(parent_ec);
           }
      }
 
@@ -455,25 +448,19 @@ _e_eom_client_get_current_by_ec_parrent(E_Client *ec)
    Eina_List *l;
    E_EomClientPtr client;
    E_Client *parent = NULL;
-   E_Comp_Wl_Client_Data *cdata = NULL, *parent_cdata = NULL;
-
-   cdata = e_client_cdata_get(ec);
-   if (!cdata || !cdata->sub.data)
-     return NULL;
 
    EINA_LIST_FOREACH(g_eom->clients, l, client)
      {
-        parent = cdata->sub.data->parent;
+        parent = e_comp_wl_subsurface_parent_get(ec);
         while (parent)
           {
              if (client->ec == parent)
                return client;
 
-             parent_cdata = e_client_cdata_get(parent);
-             if (!parent_cdata || !parent_cdata->sub.data)
+             if (!e_comp_wl_subsurface_check(parent))
                break;
 
-             parent = parent_cdata->sub.data->parent;
+             parent = e_comp_wl_subsurface_parent_get(parent);
           }
      }
 
index 2864104..541ecac 100644 (file)
@@ -952,13 +952,13 @@ _e_hwc_window_cb_subsurface_synchronized_commit(void *data, E_Client *ec)
    Eina_Bool need_sync = EINA_FALSE;
 
    EINA_SAFETY_ON_NULL_RETURN(ec);
-   if ((!ec->hwc_window) || (!ec->comp_data) || (!ec->comp_data->sub.data)) return;
+   if ((!ec->hwc_window) || (!e_comp_wl_subsurface_check(ec))) return;
 
    state = e_hwc_window_accepted_state_get(ec->hwc_window);
    if ((state != E_HWC_WINDOW_STATE_DEVICE) && (state != E_HWC_WINDOW_STATE_VIDEO))
      return;
 
-   parent = ec->comp_data->sub.data->parent;
+   parent = e_comp_wl_subsurface_parent_get(ec);
    while (parent)
      {
         state = e_hwc_window_accepted_state_get(parent->hwc_window);
@@ -968,10 +968,10 @@ _e_hwc_window_cb_subsurface_synchronized_commit(void *data, E_Client *ec)
              break;
           }
 
-        if ((!parent->comp_data) || (!parent->comp_data->sub.data))
-          break;
+        if (!e_comp_wl_subsurface_check(parent))
+            break;
 
-        parent = parent->comp_data->sub.data->parent;
+        parent = e_comp_wl_subsurface_parent_get(parent);
      }
 
    if (need_sync)
index f044b0d..0c42233 100644 (file)
@@ -1293,8 +1293,7 @@ fail:
 static const char*
 _get_win_prop_Subsurface_Parent(const Evas_Object *evas_obj)
 {
-   const E_Comp_Wl_Client_Data *cdata;
-   const E_Client *ec;
+   const E_Client *ec, *parent;
    char *str = NULL;
 
    ec = evas_object_data_get(evas_obj, "E_Client");
@@ -1303,9 +1302,8 @@ _get_win_prop_Subsurface_Parent(const Evas_Object *evas_obj)
    if (!ec->comp_data)
      return strdup("None");
 
-   cdata = (E_Comp_Wl_Client_Data*)ec->comp_data;
-
-   if (asprintf(&str, "0x%zx", cdata->sub.data ? e_client_util_win_get(cdata->sub.data->parent) : 0) < 0)
+   parent = e_comp_wl_subsurface_parent_get((E_Client *)ec);
+   if (asprintf(&str, "0x%zx", parent ? e_client_util_win_get(parent) : 0) < 0)
      return NULL;
 
    return str;
@@ -3034,8 +3032,8 @@ _e_info_server_cb_subsurface(const Eldbus_Service_Interface *iface EINA_UNUSED,
                  !ec->comp_data->sub.below_list && !ec->comp_data->sub.below_list_pending)
                continue;
              win = e_client_util_win_get(ec);
-             if (ec->comp_data->sub.data)
-               parent = e_client_util_win_get(ec->comp_data->sub.data->parent);
+             if (e_comp_wl_subsurface_check(ec))
+               parent = e_client_util_win_get(e_comp_wl_subsurface_parent_get(ec));
              buffer = e_pixmap_resource_get(ec->pixmap);
              if (buffer)
                buf_id = (buffer->resource) ? wl_resource_get_id(buffer->resource) : (WAYLAND_SERVER_RESOURCE_ID_MASK & 99999);
index b947adf..835dfd5 100644 (file)
@@ -2055,18 +2055,12 @@ _tzpol_iface_cb_subsurf_place_below_parent(struct wl_client *client EINA_UNUSED,
 {
    E_Client *ec;
    E_Client *epc;
-   E_Comp_Wl_Client_Data *cdata, *epc_cdata;
-   E_Comp_Wl_Subsurf_Data *sdata;
+   E_Comp_Wl_Client_Data *epc_cdata;
 
    ec = wl_resource_get_user_data(subsurf);
    EINA_SAFETY_ON_NULL_RETURN(ec);
-   cdata = e_client_cdata_get(ec);
-   EINA_SAFETY_ON_NULL_RETURN(cdata);
-
-   sdata = cdata->sub.data;
-   EINA_SAFETY_ON_NULL_RETURN(sdata);
 
-   epc = sdata->parent;
+   epc = e_comp_wl_subsurface_parent_get(ec);
    EINA_SAFETY_ON_NULL_RETURN(epc);
    epc_cdata = e_client_cdata_get(epc);
    EINA_SAFETY_ON_NULL_RETURN(epc_cdata);
index eb3bb90..d3b90b6 100644 (file)
@@ -429,7 +429,6 @@ _e_process_freeze_condition_check(pid_t pid)
 {
    E_Process *pinfo  = NULL;
    E_Client *ec = NULL;
-   E_Comp_Wl_Client_Data *cdata;
    Eina_Bool freeze = EINA_TRUE;
    Eina_List *l;
 
@@ -443,10 +442,8 @@ _e_process_freeze_condition_check(pid_t pid)
 
    EINA_LIST_FOREACH(pinfo->ec_list, l, ec)
      {
-        cdata = e_client_cdata_get(ec);
-        if (cdata &&
-            cdata->sub.data &&
-            cdata->sub.data->parent)
+        if ((e_comp_wl_subsurface_check(ec)) &&
+            (e_comp_wl_subsurface_parent_get(ec)))
           continue;
 
         if (ec->visible && !ec->iconic)
index a1aed69..d6f8762 100644 (file)
@@ -245,10 +245,10 @@ _e_client_video_offscreen_parent_get(E_Client_Video *ecv)
    E_Client *ec, *parent = NULL;
 
    ec = ecv->ec;
-   if (!ec->comp_data || !ec->comp_data->sub.data)
+   if (!e_comp_wl_subsurface_check(ec))
      return NULL;
 
-   parent = ec->comp_data->sub.data->parent;
+   parent = e_comp_wl_subsurface_parent_get(ec);
    while (parent)
      {
         if (!parent->comp_data || !parent->comp_data->sub.data)
@@ -257,7 +257,7 @@ _e_client_video_offscreen_parent_get(E_Client_Video *ecv)
         if (parent->comp_data->sub.data->remote_surface.offscreen_parent)
           return parent->comp_data->sub.data->remote_surface.offscreen_parent;
 
-        parent = parent->comp_data->sub.data->parent;
+        parent = e_comp_wl_subsurface_parent_get(parent);
      }
 
    return NULL;
index 53ed8fe..6912462 100644 (file)
@@ -54,19 +54,19 @@ _e_video_hwc_client_offscreen_parent_get(E_Client *ec)
 {
    E_Client *parent = NULL;
 
-   if (!ec->comp_data || !ec->comp_data->sub.data)
+   if (!e_comp_wl_subsurface_check(ec))
      return NULL;
 
-   parent = ec->comp_data->sub.data->parent;
+   parent = e_comp_wl_subsurface_parent_get(ec);
    while (parent)
      {
-        if (!parent->comp_data || !parent->comp_data->sub.data)
+        if (!e_comp_wl_subsurface_check(parent))
           return NULL;
 
         if (parent->comp_data->sub.data->remote_surface.offscreen_parent)
           return parent->comp_data->sub.data->remote_surface.offscreen_parent;
 
-        parent = parent->comp_data->sub.data->parent;
+        parent = e_comp_wl_subsurface_parent_get(parent);
      }
 
    return NULL;