[vlc-devel] [PATCH v4 04/23] video_output: translate the mouse coordinates to display coordinates early

Steve Lhomme robux4 at ycbcr.xyz
Fri Aug 21 11:59:22 CEST 2020


We can do this in the UI thread, the processing is light.
Locking the display_lock doesn't have a big impact on lag as it's only taking
time when reloading a display module, which is very rare.
---
 src/video_output/video_output.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index c6a034be46f..538f892947a 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -388,7 +388,14 @@ void vout_MouseState(vout_thread_t *vout, const vlc_mouse_t *mouse)
     assert(mouse);
     vout_control_cmd_t cmd;
     vout_control_cmd_Init(&cmd, VOUT_CONTROL_MOUSE_STATE);
-    cmd.mouse = *mouse;
+
+    /* Translate window coordinates to video coordinates */
+    vlc_mutex_lock(&sys->display_lock);
+    if (sys->display)
+        vout_display_TranslateMouseState(sys->display, &cmd.mouse, mouse);
+    else
+        cmd.mouse = *mouse;
+    vlc_mutex_unlock(&sys->display_lock);
 
     vout_control_Push(&sys->control, &cmd);
 }
@@ -1624,17 +1631,13 @@ void vout_ChangeSpuRate(vout_thread_t *vout, size_t channel_id, float rate)
 static void ThreadProcessMouseState(vout_thread_sys_t *p_vout,
                                     const vlc_mouse_t *win_mouse)
 {
-    vlc_mouse_t vid_mouse, tmp1, tmp2, *m;
+    vlc_mouse_t tmp1, tmp2;
+    const vlc_mouse_t *m;
     vout_thread_t *vout = &p_vout->obj;
     vout_thread_sys_t *sys = p_vout;
 
-    /* Translate window coordinates to video coordinates */
-    vlc_mutex_lock(&sys->display_lock);
-    vout_display_TranslateMouseState(sys->display, &vid_mouse, win_mouse);
-    vlc_mutex_unlock(&sys->display_lock);
-
-    /* Then pass up the filter chains. */
-    m = &vid_mouse;
+    /* pass mouse coordinates in the filter chains. */
+    m = win_mouse;
     vlc_mutex_lock(&sys->filter.lock);
     if (sys->filter.chain_static && sys->filter.chain_interactive) {
         if (!filter_chain_MouseFilter(sys->filter.chain_interactive,
-- 
2.26.2



More information about the vlc-devel mailing list