[vlc-devel] [PATCH 02/17] video_output: translate the mouse coordinates to display coordinates early

Steve Lhomme robux4 at ycbcr.xyz
Mon Sep 14 16:03:13 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 cbc66b9dbc0..ed1e3bfcb07 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -389,7 +389,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);
 }
@@ -1678,17 +1685,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