[vlc-commits] window: use separate constant callback structure

Rémi Denis-Courmont git at videolan.org
Sun May 20 19:51:06 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed May 16 21:20:17 2018 +0300| [db3194e497cb6907bd0b529b1796bcdb6521d4e9] | committer: Rémi Denis-Courmont

window: use separate constant callback structure

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

 include/vlc_vout_window.h | 21 +++++++++++++--------
 src/video_output/opengl.c |  5 ++++-
 src/video_output/window.c | 10 +++++++---
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/include/vlc_vout_window.h b/include/vlc_vout_window.h
index 28e236cf47..65bef05f4b 100644
--- a/include/vlc_vout_window.h
+++ b/include/vlc_vout_window.h
@@ -116,11 +116,16 @@ typedef struct vout_window_cfg_t {
 
 } vout_window_cfg_t;
 
-typedef struct vout_window_owner {
-    void *sys;
+struct vout_window_callbacks {
     void (*resized)(vout_window_t *, unsigned width, unsigned height);
     void (*closed)(vout_window_t *);
-    void (*mouse_event)(vout_window_t *, const vout_window_mouse_event_t *mouse);
+    void (*mouse_event)(vout_window_t *,
+                        const vout_window_mouse_event_t *mouse);
+};
+
+typedef struct vout_window_owner {
+    const struct vout_window_callbacks *cbs;
+    void *sys;
 } vout_window_owner_t;
 
 /**
@@ -296,20 +301,20 @@ static inline int vout_window_HideMouse(vout_window_t *window, bool hide)
 static inline void vout_window_ReportSize(vout_window_t *window,
                                           unsigned width, unsigned height)
 {
-    window->owner.resized(window, width, height);
+    window->owner.cbs->resized(window, width, height);
 }
 
 static inline void vout_window_ReportClose(vout_window_t *window)
 {
-    if (window->owner.closed != NULL)
-        window->owner.closed(window);
+    if (window->owner.cbs->closed != NULL)
+        window->owner.cbs->closed(window);
 }
 
 static inline void vout_window_SendMouseEvent(vout_window_t *window,
                                               const vout_window_mouse_event_t *mouse)
 {
-    if (window->owner.mouse_event != NULL)
-        window->owner.mouse_event(window, mouse);
+    if (window->owner.cbs->mouse_event != NULL)
+        window->owner.cbs->mouse_event(window, mouse);
 }
 
 /**
diff --git a/src/video_output/opengl.c b/src/video_output/opengl.c
index b700fa4637..f5f19085d2 100644
--- a/src/video_output/opengl.c
+++ b/src/video_output/opengl.c
@@ -131,9 +131,12 @@ vlc_gl_t *vlc_gl_surface_Create(vlc_object_t *obj,
     sys->height = cfg->height;
     vlc_mutex_init(&sys->lock);
 
+    static const struct vout_window_callbacks cbs = {
+        .resized = vlc_gl_surface_ResizeNotify,
+    };
     vout_window_owner_t owner = {
+        .cbs = &cbs,
         .sys = sys,
-        .resized = vlc_gl_surface_ResizeNotify,
     };
     char *modlist = var_InheritString(obj, "window");
 
diff --git a/src/video_output/window.c b/src/video_output/window.c
index a307c5be58..64e3b8ccf7 100644
--- a/src/video_output/window.c
+++ b/src/video_output/window.c
@@ -163,6 +163,12 @@ static void vout_display_window_MouseEvent(vout_window_t *window,
     vout_WindowMouseEvent(vout, mouse);
 }
 
+static const struct vout_window_callbacks vout_display_window_cbs = {
+    .resized = vout_display_window_ResizeNotify,
+    .closed = vout_display_window_CloseNotify,
+    .mouse_event = vout_display_window_MouseEvent,
+};
+
 /**
  * Creates a video window, initially without any attached display.
  */
@@ -180,10 +186,8 @@ vout_window_t *vout_display_window_New(vout_thread_t *vout,
 
     char *modlist = var_InheritString(vout, "window");
     vout_window_owner_t owner = {
+        .cbs = &vout_display_window_cbs,
         .sys = state,
-        .resized = vout_display_window_ResizeNotify,
-        .closed = vout_display_window_CloseNotify,
-        .mouse_event = vout_display_window_MouseEvent,
     };
     vout_window_t *window;
 



More information about the vlc-commits mailing list