subsurface: create 'wl_resource' for wl_subsurface at one place. 24/241224/3
authorSeunghun Lee <shiin.lee@samsung.com>
Wed, 13 May 2020 09:09:59 +0000 (18:09 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Sun, 23 Aug 2020 23:36:46 +0000 (23:36 +0000)
Change-Id: I1aeab454ee00e09f14abaf4232b2598fe1099245

src/bin/e_comp_wl_subsurface.c

index a71e73f34dc8ab982f6cea3e776ac6ee787bc36e..d5329235c2d477f0d8f24f0a0b924c880aa39688 100644 (file)
@@ -6,7 +6,7 @@ static struct wl_global *global = NULL;
 static Eina_List *hooks = NULL;
 
 static Eina_Bool  _e_comp_wl_subsurface_circular_reference_check(E_Client *ec, E_Client *parent);
-static void       _e_comp_wl_subsurface_invalid_parent_handle(E_Client *ec, struct wl_client *client, uint32_t id);
+static void       _e_comp_wl_subsurface_invalid_parent_handle(E_Client *ec, struct wl_resource *resource);
 
 static void
 _e_comp_wl_subsurface_restack_bg_rectangle(E_Client *ec)
@@ -880,10 +880,18 @@ e_comp_wl_subsurface_create(E_Client *ec, E_Client *epc, uint32_t id, struct wl_
 
    if (e_object_is_del(E_OBJECT(ec)) || !ec->comp_data) return EINA_FALSE;
 
+   res = wl_resource_create(client, &wl_subsurface_interface, 1, id);
+   if (!res)
+     {
+        ERR("Failed to create subsurface resource");
+        wl_resource_post_no_memory(surface_resource);
+        return EINA_FALSE;
+     }
+
    if (!epc || e_object_is_del(E_OBJECT(epc)))
      {
         ERR("tizen_policy failed: invalid parent");
-        _e_comp_wl_subsurface_invalid_parent_handle(ec, client, id);
+        _e_comp_wl_subsurface_invalid_parent_handle(ec, res);
         return EINA_FALSE;
      }
 
@@ -900,6 +908,7 @@ e_comp_wl_subsurface_create(E_Client *ec, E_Client *epc, uint32_t id, struct wl_
         ERR("Subsurface parent relationship is a cycle : [child win : %zx, %s], [parent win : %zx, %s]",
             e_client_util_win_get(ec), e_client_util_name_get(ec),
             e_client_util_win_get(epc), e_client_util_name_get(epc));
+        wl_resource_destroy(res);
         return EINA_FALSE;
      }
 
@@ -907,15 +916,8 @@ e_comp_wl_subsurface_create(E_Client *ec, E_Client *epc, uint32_t id, struct wl_
    if (!(sdata = E_NEW(E_Comp_Wl_Subsurf_Data, 1)))
      {
         ERR("Could not allocate space for subsurface data");
-        goto dat_err;
-     }
-
-   /* try to create the subsurface resource */
-   if (!(res = wl_resource_create(client, &wl_subsurface_interface, 1, id)))
-     {
-        ERR("Failed to create subsurface resource");
-        wl_resource_post_no_memory(surface_resource);
-        goto res_err;
+        wl_resource_destroy(res);
+        return EINA_FALSE;
      }
 
    /* set resource implementation */
@@ -988,12 +990,8 @@ e_comp_wl_subsurface_create(E_Client *ec, E_Client *epc, uint32_t id, struct wl_
    E_FREE_FUNC(ec->comp_data->sub.below_obj, evas_object_del);
 
    e_comp_wl_hook_call(E_COMP_WL_HOOK_SUBSURFACE_CREATE, ec);
-   return EINA_TRUE;
 
-res_err:
-   free(sdata);
-dat_err:
-   return EINA_FALSE;
+   return EINA_TRUE;
 }
 
 EINTERN void
@@ -1239,10 +1237,8 @@ static const struct wl_subsurface_interface _e_subsurface_dummy_interface =
 };
 
 static void
-_e_comp_wl_subsurface_invalid_parent_handle(E_Client *ec, struct wl_client *client, uint32_t id)
+_e_comp_wl_subsurface_invalid_parent_handle(E_Client *ec, struct wl_resource *resource)
 {
-   struct wl_resource *res;
-
    if (ec->comp_data->sub.watcher)
      tizen_subsurface_watcher_send_message(ec->comp_data->sub.watcher, TIZEN_SUBSURFACE_WATCHER_MSG_PARENT_ID_INVALID);
 
@@ -1250,12 +1246,5 @@ _e_comp_wl_subsurface_invalid_parent_handle(E_Client *ec, struct wl_client *clie
     * because server will send the fatal error when a client destroy a subsurface object.
     * Otherwise, server will kill a client by the fatal error.
     */
-   if (!(res = wl_resource_create(client, &wl_subsurface_interface, 1, id)))
-     {
-        ERR("Failed to create subsurface resource");
-        wl_client_post_no_memory(client);
-        return;
-     }
-
-   wl_resource_set_implementation(res, &_e_subsurface_dummy_interface, NULL, NULL);
+   wl_resource_set_implementation(resource, &_e_subsurface_dummy_interface, NULL, NULL);
 }