[vlc-commits] XDG shell: add private context for output list

Rémi Denis-Courmont git at videolan.org
Sun Oct 6 21:24:55 CEST 2019


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct  6 13:25:17 2019 +0300| [080c0c5cfef25cb8167f973f2f8d446b32918586] | committer: Rémi Denis-Courmont

XDG shell: add private context for output list

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=080c0c5cfef25cb8167f973f2f8d446b32918586
---

 modules/video_output/wayland/output.c    | 51 +++++++++++++++++++++++++-------
 modules/video_output/wayland/output.h    | 11 +++----
 modules/video_output/wayland/xdg-shell.c | 13 ++++----
 3 files changed, 54 insertions(+), 21 deletions(-)

diff --git a/modules/video_output/wayland/output.c b/modules/video_output/wayland/output.c
index 904132f8fd..e77b2c8999 100644
--- a/modules/video_output/wayland/output.c
+++ b/modules/video_output/wayland/output.c
@@ -34,6 +34,12 @@
 
 /* TODO: xdg_output protocol */
 
+struct output_list
+{
+    vout_window_t *owner;
+    struct wl_list outputs;
+};
+
 struct output_data
 {
     vout_window_t *owner;
@@ -101,9 +107,23 @@ static const struct wl_output_listener wl_output_cbs =
     output_scale_cb,
 };
 
-int output_create(vout_window_t *wnd, struct wl_registry *registry,
-                  uint32_t name, uint32_t version, struct wl_list *list)
+struct output_list *output_list_create(vout_window_t *wnd)
+{
+    struct output_list *ol = malloc(sizeof (*ol));
+    if (unlikely(ol == NULL))
+        return NULL;
+
+    ol->owner = wnd;
+    wl_list_init(&ol->outputs);
+    return ol;
+}
+
+int output_create(struct output_list *ol, struct wl_registry *registry,
+                  uint32_t name, uint32_t version)
 {
+    if (unlikely(ol == NULL))
+        return -1;
+
     struct output_data *od = malloc(sizeof (*od));
     if (unlikely(od == NULL))
         return -1;
@@ -119,21 +139,21 @@ int output_create(vout_window_t *wnd, struct wl_registry *registry,
         return -1;
     }
 
-    od->owner = wnd;
+    od->owner = ol->owner;
     od->name = name;
     od->version = version;
 
     wl_output_add_listener(od->wl_output, &wl_output_cbs, od);
-    wl_list_insert(list, &od->node);
+    wl_list_insert(&ol->outputs, &od->node);
     return 0;
 }
 
-static void output_destroy(struct output_data *od)
+static void output_destroy(struct output_list *ol, struct output_data *od)
 {
     char idstr[11];
 
     sprintf(idstr, "%"PRIu32, od->name);
-    vout_window_ReportOutputDevice(od->owner, idstr, NULL);
+    vout_window_ReportOutputDevice(ol->owner, idstr, NULL);
 
     wl_list_remove(&od->node);
 
@@ -144,15 +164,19 @@ static void output_destroy(struct output_data *od)
     free(od);
 }
 
-int output_destroy_one(struct wl_list *list, uint32_t name)
+int output_destroy_by_name(struct output_list *ol, uint32_t name)
 {
+    if (unlikely(ol == NULL))
+        return -1;
+
+    struct wl_list *list = &ol->outputs;
     struct output_data *od;
 
     wl_list_for_each(od, list, node)
     {
         if (od->name == name)
         {
-            output_destroy(od);
+            output_destroy(ol, od);
             /* Note: return here so no needs for safe walk variant */
             return 0;
         }
@@ -161,8 +185,15 @@ int output_destroy_one(struct wl_list *list, uint32_t name)
     return -1;
 }
 
-void output_destroy_all(struct wl_list *list)
+void output_list_destroy(struct output_list *ol)
 {
+    if (ol == NULL)
+        return;
+
+    struct wl_list *list = &ol->outputs;
+
     while (!wl_list_empty(list))
-        output_destroy(container_of(list->next, struct output_data, node));
+        output_destroy(ol, container_of(list->next, struct output_data, node));
+
+    free(ol);
 }
diff --git a/modules/video_output/wayland/output.h b/modules/video_output/wayland/output.h
index 7d6710d90e..c7b7afdcba 100644
--- a/modules/video_output/wayland/output.h
+++ b/modules/video_output/wayland/output.h
@@ -20,9 +20,10 @@
 
 struct vout_window_t;
 struct wl_registry;
-struct wl_list;
+struct output_list;
 
-int output_create(struct vout_window_t *wnd, struct wl_registry *,
-                  uint32_t name, uint32_t version, struct wl_list *list);
-int output_destroy_one(struct wl_list *list, uint32_t name);
-void output_destroy_all(struct wl_list *list);
+struct output_list *output_list_create(struct vout_window_t *wnd);
+int output_create(struct output_list *, struct wl_registry *,
+                  uint32_t name, uint32_t version);
+int output_destroy_by_name(struct output_list *, uint32_t name);
+void output_list_destroy(struct output_list *);
diff --git a/modules/video_output/wayland/xdg-shell.c b/modules/video_output/wayland/xdg-shell.c
index 48e7679f3a..db76124f23 100644
--- a/modules/video_output/wayland/xdg-shell.c
+++ b/modules/video_output/wayland/xdg-shell.c
@@ -99,7 +99,7 @@ typedef struct
         bool configured;
     } wm;
 
-    struct wl_list outputs;
+    struct output_list *outputs;
     struct wl_list seats;
     struct wl_cursor_theme *cursor_theme;
     struct wl_cursor *cursor;
@@ -440,7 +440,7 @@ static void registry_global_cb(void *data, struct wl_registry *registry,
         seat_create(wnd, registry, name, vers, &sys->seats);
     else
     if (!strcmp(iface, "wl_output"))
-        output_create(wnd, registry, name, vers, &sys->outputs);
+        output_create(sys->outputs, registry, name, vers);
 #ifdef XDG_SHELL
     else
     if (!strcmp(iface, "zxdg_decoration_manager_v1"))
@@ -459,7 +459,7 @@ static void registry_global_remove_cb(void *data, struct wl_registry *registry,
 
     if (seat_destroy_one(&sys->seats, name) == 0)
         return;
-    if (output_destroy_one(&sys->outputs, name) == 0)
+    if (output_destroy_by_name(sys->outputs, name) == 0)
         return;
 
     (void) registry;
@@ -526,7 +526,7 @@ static int Open(vout_window_t *wnd)
     sys->wm.configured = false;
     sys->set.width = 0;
     sys->set.height = 0;
-    wl_list_init(&sys->outputs);
+    sys->outputs = output_list_create(wnd);
     wl_list_init(&sys->seats);
     sys->cursor_theme = NULL;
     sys->cursor_surface = NULL;
@@ -542,6 +542,7 @@ static int Open(vout_window_t *wnd)
 
     if (display == NULL)
     {
+        output_list_destroy(sys->outputs);
         free(sys);
         return VLC_EGENERIC;
     }
@@ -625,7 +626,7 @@ static int Open(vout_window_t *wnd)
 
 error:
     seat_destroy_all(&sys->seats);
-    output_destroy_all(&sys->outputs);
+    output_list_destroy(sys->outputs);
 #ifdef XDG_SHELL
     if (sys->deco != NULL)
         zxdg_toplevel_decoration_v1_destroy(sys->deco);
@@ -667,7 +668,7 @@ static void Close(vout_window_t *wnd)
 
     vlc_mutex_destroy(&sys->lock);
     seat_destroy_all(&sys->seats);
-    output_destroy_all(&sys->outputs);
+    output_list_destroy(sys->outputs);
 #ifdef XDG_SHELL
     if (sys->deco != NULL)
         zxdg_toplevel_decoration_v1_destroy(sys->deco);



More information about the vlc-commits mailing list