comp_wl_renderer: Use ds_tizen_renderer
authorTaeHyeon Jeong <thyeon.jeong@samsung.com>
Tue, 30 Jul 2024 08:35:13 +0000 (17:35 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Fri, 30 Aug 2024 08:10:16 +0000 (17:10 +0900)
Change-Id: I7fb57a03ad7599dc4bb008868b36fa55eddcee90

src/bin/server/e_comp_wl_renderer.c

index cf23d5d..a589cdd 100644 (file)
 #include "e_comp_wl_renderer_intern.h"
 
-#include <tizen-extension-server-protocol.h>
+#include <libds-tizen/renderer.h>
 
-typedef struct _E_Comp_Wl_Renderer_Manager         E_Comp_Wl_Renderer_Manager;
-typedef struct _E_Comp_Wl_Renderer                 E_Comp_Wl_Renderer;
-typedef struct _E_Comp_Wl_Renderer_Surface         E_Comp_Wl_Renderer_Surface;
+typedef struct ds_tizen_renderer Ds_Tizen_Renderer;
+typedef struct ds_tizen_renderer_info Ds_Tizen_Renderer_Info;
 
-struct _E_Comp_Wl_Renderer_Manager
-{
-   struct wl_global *global;
-   Eina_List *renderers;
-};
-
-struct _E_Comp_Wl_Renderer
-{
-   struct wl_resource *resource;
-   Eina_List *renderer_surfaces;
-};
+typedef struct _Ds_Tizen_Renderer_Mgr {
+   Ds_Tizen_Renderer *renderer;
+   struct wl_listener renderer_info_get;
+   Eina_List *info_wrappers;
+} Ds_Tizen_Renderer_Mgr;
 
-struct _E_Comp_Wl_Renderer_Surface
-{
-   struct wl_resource *resource;
+typedef struct _Ds_Tizen_Renderer_Info_Wrapper {
+   Ds_Tizen_Renderer_Info *info;
    E_Client *ec;
    E_Object_Delfn *ec_delfn;
-   E_Comp_Wl_Renderer *renderer;
-};
+   struct wl_listener renderer_info_destroy;
+} Ds_Tizen_Renderer_Info_Wrapper;
 
-static E_Comp_Wl_Renderer_Manager *_renderer_mgr;
+static Ds_Tizen_Renderer_Mgr *renderer_mgr;
 
-static E_Comp_Wl_Renderer_Surface *
-_renderer_surface_find(E_Client *ec)
+static void _renderer_info_wrapper_cb_renderer_info_destroy(struct wl_listener *listener, void *data);
+
+static Ds_Tizen_Renderer_Info *
+_renderer_info_find(E_Client *ec)
 {
-   E_Comp_Wl_Renderer_Manager *renderer_mgr;
-   E_Comp_Wl_Renderer *renderer;
-   E_Comp_Wl_Renderer_Surface *renderer_surface;
-   Eina_List *l, *l2;
+   Ds_Tizen_Renderer_Info_Wrapper *info_wrapper;
+   Eina_List *l;
 
-   renderer_mgr = _renderer_mgr;
-   if (!renderer_mgr) return NULL;
+   if (!renderer_mgr || !renderer_mgr->renderer) return NULL;
 
-   EINA_LIST_FOREACH(renderer_mgr->renderers, l, renderer)
-     {
-        EINA_LIST_FOREACH(renderer->renderer_surfaces, l2, renderer_surface)
-          {
-             if (renderer_surface->ec == ec)
-               return renderer_surface;
-          }
-     }
+   EINA_LIST_FOREACH(renderer_mgr->info_wrappers, l, info_wrapper)
+     if (info_wrapper->ec == ec)
+       return info_wrapper->info;
 
    return NULL;
 }
 
 static void
-_renderer_surface_cb_ec_free(void *data, void *obj)
+_renderer_info_wrapper_cb_ec_free(void *data, void *obj)
 {
-   E_Comp_Wl_Renderer_Surface *renderer_surface;
+   Ds_Tizen_Renderer_Info_Wrapper *info_wrapper;
 
-   renderer_surface = (E_Comp_Wl_Renderer_Surface *)data;
-   EINA_SAFETY_ON_NULL_RETURN(renderer_surface);
+   info_wrapper = (Ds_Tizen_Renderer_Info_Wrapper *)data;
+   EINA_SAFETY_ON_NULL_RETURN(info_wrapper);
 
-   renderer_surface->ec = NULL;
-   renderer_surface->ec_delfn = NULL;
+   info_wrapper->ec = NULL;
+   info_wrapper->ec_delfn = NULL;
 }
 
 static void
-_renderer_surface_cb_destroy(struct wl_client *client, struct wl_resource *resource)
+_renderer_info_wrapper_free(Ds_Tizen_Renderer_Info_Wrapper *info_wrapper)
 {
-   wl_resource_destroy(resource);
-}
-
-static const struct tizen_renderer_surface_interface renderer_surface_implementation = {
-   _renderer_surface_cb_destroy,
-};
-
-static void
-_renderer_surface_cb_resource_destroy(struct wl_resource *renderer_surface_resource)
-{
-   E_Comp_Wl_Renderer *renderer;
-   E_Comp_Wl_Renderer_Surface *renderer_surface;
-
-   renderer_surface = wl_resource_get_user_data(renderer_surface_resource);
-   if (!renderer_surface) return;
+   renderer_mgr->info_wrappers = eina_list_remove(renderer_mgr->info_wrappers, info_wrapper);
 
-   renderer = renderer_surface->renderer;
-   if (renderer)
-     {
-        renderer->renderer_surfaces = eina_list_remove(renderer->renderer_surfaces,
-                                                       renderer_surface);
-     }
+   if ((info_wrapper->ec) && (info_wrapper->ec_delfn))
+     e_object_delfn_del(E_OBJECT(info_wrapper->ec), info_wrapper->ec_delfn);
 
-   if ((renderer_surface->ec) && (renderer_surface->ec_delfn))
-     {
-        e_object_delfn_del(E_OBJECT(renderer_surface->ec), renderer_surface->ec_delfn);
-        renderer_surface->ec_delfn = NULL;
-     }
+   wl_list_remove(&info_wrapper->renderer_info_destroy.link);
 
-   E_FREE(renderer_surface);
+   E_FREE(info_wrapper);
 }
 
 static void
-_renderer_cb_get_renderer_surface(struct wl_client *client, struct wl_resource *resource,
-                                  uint32_t id, struct wl_resource *surface_resource)
+_renderer_mgr_cb_renderer_info_get(struct wl_listener *listener, void *data)
 {
-   E_Comp_Wl_Renderer *renderer;
-   E_Comp_Wl_Renderer_Surface *renderer_surface;
-   E_Client *ec;
+   Ds_Tizen_Renderer_Info *renderer_info;
+   Ds_Tizen_Renderer_Info_Wrapper *info_wrapper;
+   E_Client *ec = NULL;
+   struct ds_surface *ds_surface;
+   struct wl_resource *surface_resource = NULL;
 
-   ec = e_client_from_surface_resource(surface_resource);
-   if (!ec) return;
-   if (e_object_is_del(E_OBJECT(ec))) return;
+   renderer_info = (Ds_Tizen_Renderer_Info *)data;
 
-   renderer = wl_resource_get_user_data(resource);
-   if (!renderer) return;
+   ds_surface = ds_tizen_renderer_info_get_surface(renderer_info);
 
-   renderer_surface = E_NEW(E_Comp_Wl_Renderer_Surface, 1);
-   if (!renderer_surface)
-     {
-        wl_client_post_no_memory(client);
-        return;
-     }
+   if (ds_surface)
+     surface_resource = ds_surface_get_wl_resource(ds_surface);
+
+   if (surface_resource)
+     ec = e_client_from_surface_resource(surface_resource);
 
-   renderer_surface->resource = wl_resource_create(client, &tizen_renderer_surface_interface, 1, id);
-   if (!renderer_surface->resource)
+   if (!ec || e_object_is_del(E_OBJECT(ec)))
+     return;
+
+   info_wrapper = E_NEW(Ds_Tizen_Renderer_Info_Wrapper, 1);
+   if (!info_wrapper)
      {
-        wl_client_post_no_memory(client);
-        E_FREE(renderer_surface);
+        ERR("Could not create tizen_renderer_info_wrapper");
         return;
      }
 
-   wl_resource_set_implementation(renderer_surface->resource, &renderer_surface_implementation,
-                                  renderer_surface, _renderer_surface_cb_resource_destroy);
-
-   renderer_surface->ec = ec;
-   renderer_surface->ec_delfn = e_object_delfn_add(E_OBJECT(ec),
-                                                   _renderer_surface_cb_ec_free,
-                                                   renderer_surface);
-
-   renderer_surface->renderer = renderer;
-   renderer->renderer_surfaces = eina_list_append(renderer->renderer_surfaces, renderer_surface);
-}
-
-static void
-_renderer_cb_destroy(struct wl_client *client, struct wl_resource *resource)
-{
-   wl_resource_destroy(resource);
-}
-
-static const struct tizen_renderer_interface renderer_implementation = {
-   _renderer_cb_get_renderer_surface,
-   _renderer_cb_destroy,
-};
-
-static void
-_renderer_cb_resource_destroy(struct wl_resource *renderer_resource)
-{
-   E_Comp_Wl_Renderer_Manager *renderer_mgr;
-   E_Comp_Wl_Renderer *renderer;
-   E_Comp_Wl_Renderer_Surface *renderer_surface;
-   Eina_List *l;
-
-   renderer = wl_resource_get_user_data(renderer_resource);
-   if (!renderer) return;
-
-   renderer_mgr = _renderer_mgr;
-   if (renderer_mgr)
-     renderer_mgr->renderers = eina_list_remove(renderer_mgr->renderers, renderer);
+   info_wrapper->info = renderer_info;
+   info_wrapper->ec = ec;
+   info_wrapper->ec_delfn = e_object_delfn_add(E_OBJECT(ec),
+                                               _renderer_info_wrapper_cb_ec_free,
+                                               info_wrapper);
 
-   EINA_LIST_FOREACH(renderer->renderer_surfaces, l, renderer_surface)
-     renderer_surface->renderer = NULL;
+   info_wrapper->renderer_info_destroy.notify = _renderer_info_wrapper_cb_renderer_info_destroy;
+   ds_tizen_renderer_info_add_destroy_listener(renderer_info,
+                                               &info_wrapper->renderer_info_destroy);
 
-   E_FREE(renderer);
+   renderer_mgr->info_wrappers = eina_list_append(renderer_mgr->info_wrappers, info_wrapper);
 }
 
 static void
-_renderer_cb_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
+_renderer_info_wrapper_cb_renderer_info_destroy(struct wl_listener *listener, void *data)
 {
-   struct wl_resource *resource;
-   E_Comp_Wl_Renderer_Manager *renderer_mgr;
-   E_Comp_Wl_Renderer *renderer;
-
-   renderer_mgr = _renderer_mgr;
-
-   renderer = E_NEW(E_Comp_Wl_Renderer, 1);
-   if (!renderer)
-     {
-        wl_client_post_no_memory(client);
-        return;
-     }
+   Ds_Tizen_Renderer_Info_Wrapper *info_wrapper;
 
-   resource = wl_resource_create(client, &tizen_renderer_interface, version, id);
-   if (!resource)
-     {
-        wl_client_post_no_memory(client);
-        E_FREE(renderer);
-        return;
-     }
-
-   wl_resource_set_implementation(resource, &renderer_implementation,
-                                  renderer, _renderer_cb_resource_destroy);
+   info_wrapper = wl_container_of(listener, info_wrapper, renderer_info_destroy);
+   if (info_wrapper->info != (Ds_Tizen_Renderer_Info *)data)
+     return;
 
-   renderer->resource = resource;
-   renderer_mgr->renderers = eina_list_append(renderer_mgr->renderers, renderer);
+   _renderer_info_wrapper_free(info_wrapper);
 }
 
 EINTERN Eina_Bool
 e_comp_wl_renderer_init(void)
 {
-   E_Comp_Wl_Renderer_Manager *renderer_mgr;
-
    EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl->wl.disp, EINA_FALSE);
 
-   if (_renderer_mgr) return EINA_TRUE;
+   if (renderer_mgr) return EINA_TRUE;
 
-   renderer_mgr = E_NEW(E_Comp_Wl_Renderer_Manager, 1);
+   renderer_mgr = E_NEW(Ds_Tizen_Renderer_Mgr, 1);
    EINA_SAFETY_ON_NULL_GOTO(renderer_mgr, fail);
 
-   renderer_mgr->global = wl_global_create(e_comp_wl->wl.disp,
-                                           &tizen_renderer_interface,
-                                           1,
-                                           NULL,
-                                           _renderer_cb_bind);
-   EINA_SAFETY_ON_NULL_GOTO(renderer_mgr->global, fail);
+   renderer_mgr->renderer = ds_tizen_renderer_create(e_comp_wl->wl.disp);
+   EINA_SAFETY_ON_NULL_GOTO(renderer_mgr->renderer, fail);
 
-   _renderer_mgr = renderer_mgr;
+   renderer_mgr->renderer_info_get.notify = _renderer_mgr_cb_renderer_info_get;
+   ds_tizen_renderer_add_get_renderer_surface_info_listener(renderer_mgr->renderer,
+                                                            &renderer_mgr->renderer_info_get);
 
    return EINA_TRUE;
 
 fail:
    if (renderer_mgr)
-     {
-        if (renderer_mgr->global)
-          wl_global_destroy(renderer_mgr->global);
-
-        E_FREE(renderer_mgr);
-     }
+     E_FREE(renderer_mgr);
 
    return EINA_FALSE;
 }
@@ -242,27 +146,30 @@ fail:
 EINTERN void
 e_comp_wl_renderer_shutdown(void)
 {
-   E_Comp_Wl_Renderer_Manager *renderer_mgr;
+   Ds_Tizen_Renderer_Info_Wrapper *info_wrapper;
+   Eina_List *l, *ll;
 
-   renderer_mgr = _renderer_mgr;
    if (!renderer_mgr) return;
 
-   wl_global_destroy(renderer_mgr->global);
-   eina_list_free(renderer_mgr->renderers);
-   E_FREE(renderer_mgr);
+   wl_list_remove(&renderer_mgr->renderer_info_get.link);
 
-   _renderer_mgr = NULL;
+   EINA_LIST_FOREACH_SAFE(renderer_mgr->info_wrappers, l, ll, info_wrapper)
+     _renderer_info_wrapper_free(info_wrapper);
+
+   eina_list_free(renderer_mgr->info_wrappers);
+
+   E_FREE(renderer_mgr);
 }
 
 EINTERN Eina_Bool
 e_comp_wl_renderer_client_redraw_request_send(E_Client *ec)
 {
-   E_Comp_Wl_Renderer_Surface *renderer_surface;
+   Ds_Tizen_Renderer_Info *renderer_info;
 
-   renderer_surface = _renderer_surface_find(ec);
-   if (!renderer_surface) return EINA_FALSE;
+   renderer_info = _renderer_info_find(ec);
+   if (!renderer_info) return EINA_FALSE;
 
-   tizen_renderer_surface_send_redraw_request(renderer_surface->resource);
+   ds_tizen_renderer_info_send_redraw(renderer_info);
 
    return EINA_TRUE;
 }