[vlc-commits] [Git][videolan/vlc][master] 19 commits: win32/common: only keep the initial window width/height

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Apr 19 12:00:17 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
9555c5d0 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32/common: only keep the initial window width/height

No need to pretend we need a rectangle.

- - - - -
fdc446ed by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32/common: pass parameters directly to EventThreadStart()

No need for a specialized structure just for that.

- - - - -
0a8633aa by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32/common: move the Sensor hook declaration in a header

- - - - -
57ab5ee1 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32/common: pass the vout_display_owner_t to the sensor code

No need to pass a whole vout_display_t.

- - - - -
f71d15f9 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32/common: handle the sensor init/close in the HWND handler

When we create the window we know if it's for a projection or not.
That's all we need to initialize the sensors.

The code is disabled for display module not using the sensor (no projection).
The code is in C++ so we don't want to pull it when we don't need to.

- - - - -
9586c126 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32/common: create+start the window handler in one call

They have to be called consecutively anyway.

- - - - -
06e8324d by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32/common: stop+destroy the window handler in one call

It's called only once, we don't need separate calls.

- - - - -
9a6bc756 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32/common: don't init b_done twice

And group flag initialization.

- - - - -
d3d73017 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32/common: remove event_thread_t typedef

- - - - -
e3bf0a9a by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32/common: reorder code to avoid forward declarations

No functional changes.

- - - - -
1e6a9726 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32touch: reorder to avoid forward declaration

No functional changes.

- - - - -
028bf179 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32touch: return whether the gesture was handled

So we don't have to pass a lot of args.

- - - - -
138d2d68 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32touch: use C11 bool instead of Windows BOOL

This is not a value we get from the Windows API's.

- - - - -
910643fb by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32touch: load gesture API statically

We only compile this code on desktop builds and the minimum version
is Windows 7, so the code should always be there.

Example: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setgestureconfig

- - - - -
33b33a96 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32touch: make win32_gesture_sys_t private

As well as enums only used in win32touch.c.

- - - - -
f69ae122 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32touch: return the valid win32_gesture_sys_t from InitGestures()

We never checked the boolean error and it's cleaner.

- - - - -
200b9019 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32touch: don't use the gesture code if SetGestureConfig() fails

- - - - -
98b51284 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32/common: translate HGESTUREINFO early

- - - - -
fb094900 by Steve Lhomme at 2023-04-19T06:31:11+00:00
win32touch: avoid local variable to handle the code logic

- - - - -


12 changed files:

- modules/video_output/Makefile.am
- modules/video_output/win32/common.c
- modules/video_output/win32/common.h
- modules/video_output/win32/direct3d11.cpp
- modules/video_output/win32/events.c
- modules/video_output/win32/events.h
- modules/video_output/win32/glwin32.c
- modules/video_output/win32/meson.build
- modules/video_output/win32/sensors.cpp
- + modules/video_output/win32/sensors.h
- modules/video_output/win32/win32touch.c
- modules/video_output/win32/win32touch.h


Changes:

=====================================
modules/video_output/Makefile.am
=====================================
@@ -168,7 +168,7 @@ libdirect3d9_plugin_la_SOURCES = video_output/win32/direct3d9.c \
 	video_output/win32/events.c video_output/win32/events.h \
 	video_output/win32/builtin_shaders.h \
 	video_output/win32/win32touch.c video_output/win32/win32touch.h
-libdirect3d9_plugin_la_LIBADD = libchroma_copy.la libd3d9_common.la -lgdi32 $(LIBCOM) -luuid
+libdirect3d9_plugin_la_LIBADD = libchroma_copy.la libd3d9_common.la -lgdi32 -luser32 $(LIBCOM) -luuid
 libdirect3d9_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
 
 libglinterop_dxva2_plugin_la_SOURCES = video_output/opengl/interop_dxva2.c \
@@ -193,14 +193,16 @@ libdirect3d11_plugin_la_SOURCES = video_output/win32/direct3d11.cpp \
  video_output/win32/common.c video_output/win32/common.h
 libdirect3d11_plugin_la_CXXFLAGS = $(AM_CXXFLAGS) $(LIBCOMCXXFLAGS)
 libdirect3d11_plugin_la_LIBADD = libchroma_copy.la libd3d11_common.la $(LIBCOM) -luuid
+libdirect3d11_plugin_la_CPPFLAGS = $(AM_CPPFLAGS)
 if !HAVE_WINSTORE
+libdirect3d11_plugin_la_CPPFLAGS += -DHAVE_WIN32_SENSORS
 libdirect3d11_plugin_la_SOURCES += video_output/win32/events.c \
  video_output/win32/events.h \
  video_output/win32/d3d11_swapchain.cpp video_output/win32/d3d11_swapchain.h \
  video_output/win32/dxgi_swapchain.cpp video_output/win32/dxgi_swapchain.h \
  video_output/win32/sensors.cpp \
  video_output/win32/win32touch.c video_output/win32/win32touch.h
-libdirect3d11_plugin_la_LIBADD += -lgdi32
+libdirect3d11_plugin_la_LIBADD += -lgdi32 -luser32
 else
 libdirect3d11_plugin_la_LIBADD += -ld3d11
 libdirect3d11_plugin_la_LIBADD += -ld3dcompiler_47
@@ -215,10 +217,11 @@ libglwin32_plugin_la_SOURCES = $(OPENGL_VOUT_COMMONSOURCES) \
 	video_output/win32/events.c video_output/win32/events.h \
 	video_output/win32/sensors.cpp \
 	video_output/win32/win32touch.c video_output/win32/win32touch.h
+libglwin32_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -DHAVE_WIN32_SENSORS
 libglwin32_plugin_la_CXXFLAGS = $(AM_CXXFLAGS) $(LIBCOMCXXFLAGS)
 libwgl_plugin_la_SOURCES = video_output/win32/wgl.c
 
-libglwin32_plugin_la_LIBADD = libchroma_copy.la -lopengl32 -lgdi32 $(LIBCOM) -luuid libvlc_opengl.la
+libglwin32_plugin_la_LIBADD = libchroma_copy.la -lopengl32 -lgdi32 -luser32 $(LIBCOM) -luuid libvlc_opengl.la
 libwgl_plugin_la_LIBADD = -lopengl32 -lgdi32 libvlc_opengl.la
 
 libglwin32_plugin_la_CFLAGS = $(AM_CFLAGS) $(OPENGL_COMMONCFLAGS)
@@ -236,7 +239,7 @@ libwingdi_plugin_la_SOURCES = video_output/win32/wingdi.c \
 	video_output/win32/common.c video_output/win32/common.h \
 	video_output/win32/events.c video_output/win32/events.h \
 	video_output/win32/win32touch.c video_output/win32/win32touch.h
-libwingdi_plugin_la_LIBADD = libchroma_copy.la -lgdi32 $(LIBCOM) -luuid
+libwingdi_plugin_la_LIBADD = libchroma_copy.la -lgdi32 -luser32 $(LIBCOM) -luuid
 if HAVE_WIN32_DESKTOP
 vout_LTLIBRARIES += libwingdi_plugin.la
 endif


=====================================
modules/video_output/win32/common.c
=====================================
@@ -57,20 +57,12 @@ int CommonWindowInit(vout_display_t *vd, display_win32_area_t *area,
         return VLC_EGENERIC;
 
     /* */
-    area->event = EventThreadCreate(VLC_OBJECT(vd), vd->cfg->window);
+    area->event = EventThreadCreate(VLC_OBJECT(vd), vd->cfg->window,
+                                    &vd->cfg->display,
+                                    projection_gestures ? &vd->owner : NULL);
     if (!area->event)
         return VLC_EGENERIC;
 
-    /* */
-    event_cfg_t cfg;
-    memset(&cfg, 0, sizeof(cfg));
-    cfg.width  = vd->cfg->display.width;
-    cfg.height = vd->cfg->display.height;
-    cfg.is_projected = projection_gestures;
-
-    if (EventThreadStart(area->event, &cfg))
-        return VLC_EGENERIC;
-
     return VLC_SUCCESS;
 }
 
@@ -113,10 +105,7 @@ void CommonPlacePicture(vout_display_t *vd, display_win32_area_t *area)
 /* */
 void CommonWindowClean(display_win32_area_t *sys)
 {
-    if (sys->event) {
-        EventThreadStop(sys->event);
-        EventThreadDestroy(sys->event);
-    }
+    EventThreadDestroy(sys->event);
 }
 #endif /* !VLC_WINSTORE_APP */
 


=====================================
modules/video_output/win32/common.h
=====================================
@@ -59,9 +59,6 @@ void CommonControl(vout_display_t *, display_win32_area_t *, int );
 void CommonPlacePicture (vout_display_t *, display_win32_area_t *);
 
 void CommonInit(display_win32_area_t *, const video_format_t *);
-
-void* HookWindowsSensors(vout_display_t*, HWND);
-void UnhookWindowsSensors(void*);
 # ifdef __cplusplus
 }
 # endif


=====================================
modules/video_output/win32/direct3d11.cpp
=====================================
@@ -99,9 +99,6 @@ typedef struct vout_display_sys_t
 
     int                      log_level;
 
-    /* Sensors */
-    void *p_sensors = NULL;
-
     display_info_t           display = {};
 
     d3d11_device_t           *d3d_dev = NULL;
@@ -430,11 +427,6 @@ static int Open(vout_display_t *vd,
 #endif // !VLC_WINSTORE_APP
     }
 
-#ifndef VLC_WINSTORE_APP
-    if (vd->source->projection_mode != PROJECTION_MODE_RECTANGULAR && CommonVideoHWND(&sys->area))
-        sys->p_sensors = HookWindowsSensors(vd, CommonVideoHWND(&sys->area));
-#endif // !VLC_WINSTORE_APP
-
     if (Direct3D11Open(vd, fmtp, context)) {
         msg_Err(vd, "Direct3D11 could not be opened");
         goto error;
@@ -471,7 +463,6 @@ static void Close(vout_display_t *vd)
     vout_display_sys_t *sys = static_cast<vout_display_sys_t *>(vd->sys);
     D3D_ReleaseShaderCompiler(sys->shaders);
 #ifndef VLC_WINSTORE_APP
-    UnhookWindowsSensors(sys->p_sensors);
     CommonWindowClean(&sys->area);
 #endif
     Direct3D11Close(vd);


=====================================
modules/video_output/win32/events.c
=====================================
@@ -41,6 +41,9 @@
 
 #include "events.h"
 #include "common.h"
+#ifdef HAVE_WIN32_SENSORS
+#include "sensors.h"
+#endif
 
 /*****************************************************************************
  * Local prototypes.
@@ -53,17 +56,20 @@ struct event_thread_t
     vlc_thread_t thread;
     vlc_mutex_t  lock;
     vlc_cond_t   wait;
-    bool         b_ready;
-    atomic_bool  b_done;
+    bool         b_ready; // the thread was started
     bool         b_error;
+    atomic_bool  b_done;
 
-    /* */
-    bool is_projected;
+#ifdef HAVE_WIN32_SENSORS
+    /* Sensors */
+    const vout_display_owner_t *init_move;
+    void *p_sensors;
+#endif
 
     /* Gestures */
-    win32_gesture_sys_t *p_gesture;
+    struct win32_gesture_sys_t *p_gesture;
 
-    RECT window_area;
+    unsigned init_width, init_height;
 
     /* */
     vlc_window_t *parent_window;
@@ -72,148 +78,14 @@ struct event_thread_t
     HWND hvideownd;
 };
 
-/***************************
- * Local Prototypes        *
- ***************************/
-/* Window Creation */
-static int  Win32VoutCreateWindow( event_thread_t * );
-static void Win32VoutCloseWindow ( event_thread_t * );
-
-/*****************************************************************************
- * EventThread: Create video window & handle its messages
- *****************************************************************************
- * This function creates a video window and then enters an infinite loop
- * that handles the messages sent to that window.
- * The main goal of this thread is to isolate the Win32 PeekMessage function
- * because this one can block for a long time.
- *****************************************************************************/
-static void *EventThread( void *p_this )
-{
-    vlc_thread_set_name("vlc-vout-hwnd");
-
-    event_thread_t *p_event = (event_thread_t *)p_this;
-    MSG msg;
-    int canc = vlc_savecancel ();
-
-
-    vlc_mutex_lock( &p_event->lock );
-    /* Create a window for the video */
-    /* Creating a window under Windows also initializes the thread's event
-     * message queue */
-    if( Win32VoutCreateWindow( p_event ) )
-        p_event->b_error = true;
-
-    p_event->b_ready = true;
-    vlc_cond_signal( &p_event->wait );
-
-    const bool b_error = p_event->b_error;
-    vlc_mutex_unlock( &p_event->lock );
-
-    if( b_error )
-    {
-        vlc_restorecancel( canc );
-        return NULL;
-    }
-
-    /* Main loop */
-    /* GetMessage will sleep if there's no message in the queue */
-    for( ;; )
-    {
-        if( !GetMessage( &msg, 0, 0, 0 ) || atomic_load( &p_event->b_done ) )
-        {
-            break;
-        }
-
-        /* Messages we don't handle directly are dispatched to the
-         * window procedure */
-        TranslateMessage(&msg);
-        DispatchMessage(&msg);
-
-    } /* End Main loop */
-
-    msg_Dbg( p_event->obj, "Win32 Vout EventThread terminating" );
-
-    Win32VoutCloseWindow( p_event );
-    vlc_restorecancel(canc);
-    return NULL;
-}
-
-event_thread_t *EventThreadCreate( vlc_object_t *obj, vlc_window_t *parent_window)
-{
-    if (parent_window->type != VLC_WINDOW_TYPE_HWND)
-        return NULL;
-     /* Create the Vout EventThread, this thread is created by us to isolate
-     * the Win32 PeekMessage function calls. We want to do this because
-     * Windows can stay blocked inside this call for a long time, and when
-     * this happens it thus blocks vlc's video_output thread.
-     * Vout EventThread will take care of the creation of the video
-     * window (because PeekMessage has to be called from the same thread which
-     * created the window). */
-    msg_Dbg( obj, "creating Vout EventThread" );
-    event_thread_t *p_event = malloc( sizeof(*p_event) );
-    if( !p_event )
-        return NULL;
-
-    p_event->obj = obj;
-    vlc_mutex_init( &p_event->lock );
-    vlc_cond_init( &p_event->wait );
-    atomic_init( &p_event->b_done, false );
-
-    p_event->parent_window = parent_window;
-
-    _snwprintf( p_event->class_video, ARRAY_SIZE(p_event->class_video),
-                TEXT("VLC video output %p"), (void *)p_event );
-    return p_event;
-}
-
-void EventThreadDestroy( event_thread_t *p_event )
-{
-    free( p_event );
-}
-
-int EventThreadStart( event_thread_t *p_event, const event_cfg_t *p_cfg )
-{
-    p_event->is_projected = p_cfg->is_projected;
-    p_event->window_area.left   = 0;
-    p_event->window_area.top    = 0;
-    p_event->window_area.right  = p_cfg->width;
-    p_event->window_area.bottom = p_cfg->height;
-
-    p_event->b_ready = false;
-    atomic_store( &p_event->b_done, false);
-    p_event->b_error = false;
-
-    if( vlc_clone( &p_event->thread, EventThread, p_event ) )
-    {
-        msg_Err( p_event->obj, "cannot create Vout EventThread" );
-        return VLC_EGENERIC;
-    }
-
-    vlc_mutex_lock( &p_event->lock );
-    while( !p_event->b_ready )
-        vlc_cond_wait( &p_event->wait, &p_event->lock );
-    const bool b_error = p_event->b_error;
-    vlc_mutex_unlock( &p_event->lock );
-
-    if( b_error )
-    {
-        vlc_join( p_event->thread, NULL );
-        p_event->b_ready = false;
-        return VLC_EGENERIC;
-    }
-    msg_Dbg( p_event->obj, "Vout EventThread running" );
-
-    return VLC_SUCCESS;
-}
-
-HWND EventThreadVideoHWND( const event_thread_t *p_event )
+HWND EventThreadVideoHWND( const struct event_thread_t *p_event )
 {
     return p_event->hvideownd;
 }
 
-void EventThreadStop( event_thread_t *p_event )
+void EventThreadDestroy( struct event_thread_t *p_event )
 {
-    if( !p_event->b_ready )
+    if ( p_event == NULL )
         return;
 
     atomic_store( &p_event->b_done, true );
@@ -224,9 +96,14 @@ void EventThreadStop( event_thread_t *p_event )
         PostMessage( p_event->hvideownd, WM_NULL, 0, 0);
 
     vlc_join( p_event->thread, NULL );
-    p_event->b_ready = false;
-}
 
+#ifdef HAVE_WIN32_SENSORS
+    if (p_event->p_sensors)
+        UnhookWindowsSensors(p_event->p_sensors);
+#endif
+
+    free( p_event );
+}
 
 /***********************************
  * Local functions implementations *
@@ -245,7 +122,7 @@ static LRESULT CALLBACK VideoEventProc( HWND hwnd, UINT message,
     LONG_PTR p_user_data = GetWindowLongPtr( hwnd, GWLP_USERDATA );
     if( p_user_data == 0 ) /* messages before WM_CREATE */
         return DefWindowProc(hwnd, message, wParam, lParam);
-    event_thread_t *p_event = (event_thread_t *)p_user_data;
+    struct event_thread_t *p_event = (struct event_thread_t *)p_user_data;
 
     switch( message )
     {
@@ -262,7 +139,9 @@ static LRESULT CALLBACK VideoEventProc( HWND hwnd, UINT message,
         return 0;
 
     case WM_GESTURE:
-        return DecodeGesture( p_event->obj, p_event->p_gesture, hwnd, message, wParam, lParam );
+        if (DecodeGesture( p_event->obj, p_event->p_gesture, (HGESTUREINFO)lParam ))
+            return 0;
+        return DefWindowProc(hwnd, message, wParam, lParam);
 
     /*
     ** For OpenGL and Direct3D, vout will update the whole
@@ -289,7 +168,7 @@ static LRESULT CALLBACK VideoEventProc( HWND hwnd, UINT message,
  * the video will be displayed. This window will also allow us to capture the
  * events.
  *****************************************************************************/
-static int Win32VoutCreateWindow( event_thread_t *p_event )
+static int Win32VoutCreateWindow( struct event_thread_t *p_event )
 {
     HINSTANCE  hInstance;
     WNDCLASS   wc;                            /* window class components */
@@ -333,8 +212,8 @@ static int Win32VoutCreateWindow( event_thread_t *p_event )
                     i_style,                                 /* window style */
                     CW_USEDEFAULT,                   /* default X coordinate */
                     CW_USEDEFAULT,                   /* default Y coordinate */
-                    RECTWidth(p_event->window_area),         /* window width */
-                    RECTHeight(p_event->window_area),       /* window height */
+                    p_event->init_width,                     /* window width */
+                    p_event->init_height,                   /* window height */
                     p_event->hparent,                       /* parent window */
                     NULL,                          /* no menu in this window */
                     hInstance,            /* handle of this program instance */
@@ -354,7 +233,12 @@ static int Win32VoutCreateWindow( event_thread_t *p_event )
         SetWindowLong( p_event->hparent, GWL_STYLE,
                        parent_style | WS_CLIPCHILDREN );
 
-    InitGestures( p_event->hvideownd, &p_event->p_gesture, p_event->is_projected );
+#ifdef HAVE_WIN32_SENSORS
+    if (p_event->init_move != NULL)
+        p_event->p_gesture = InitGestures( p_event->hvideownd, true );
+    else
+#endif
+        p_event->p_gesture = InitGestures( p_event->hvideownd, false );
 
     /* Now display the window */
     ShowWindow( p_event->hvideownd, SW_SHOWNOACTIVATE );
@@ -367,7 +251,7 @@ static int Win32VoutCreateWindow( event_thread_t *p_event )
  *****************************************************************************
  * This function returns all resources allocated by Win32VoutCreateWindow.
  *****************************************************************************/
-static void Win32VoutCloseWindow( event_thread_t *p_event )
+static void Win32VoutCloseWindow( struct event_thread_t *p_event )
 {
     msg_Dbg( p_event->obj, "Win32VoutCloseWindow" );
 
@@ -379,7 +263,134 @@ static void Win32VoutCloseWindow( event_thread_t *p_event )
     CloseGestures( p_event->p_gesture);
 }
 
-void EventThreadUpdateSize( event_thread_t *p_event )
+/*****************************************************************************
+ * EventThread: Create video window & handle its messages
+ *****************************************************************************
+ * This function creates a video window and then enters an infinite loop
+ * that handles the messages sent to that window.
+ * The main goal of this thread is to isolate the Win32 PeekMessage function
+ * because this one can block for a long time.
+ *****************************************************************************/
+static void *EventThread( void *p_this )
+{
+    vlc_thread_set_name("vlc-vout-hwnd");
+
+    struct event_thread_t *p_event = p_this;
+    MSG msg;
+    int canc = vlc_savecancel ();
+
+
+    vlc_mutex_lock( &p_event->lock );
+    /* Create a window for the video */
+    /* Creating a window under Windows also initializes the thread's event
+     * message queue */
+    if( Win32VoutCreateWindow( p_event ) )
+        p_event->b_error = true;
+
+    p_event->b_ready = true;
+    vlc_cond_signal( &p_event->wait );
+
+    const bool b_error = p_event->b_error;
+    vlc_mutex_unlock( &p_event->lock );
+
+    if( b_error )
+    {
+        vlc_restorecancel( canc );
+        return NULL;
+    }
+
+    /* Main loop */
+    /* GetMessage will sleep if there's no message in the queue */
+    for( ;; )
+    {
+        if( !GetMessage( &msg, 0, 0, 0 ) || atomic_load( &p_event->b_done ) )
+        {
+            break;
+        }
+
+        /* Messages we don't handle directly are dispatched to the
+         * window procedure */
+        TranslateMessage(&msg);
+        DispatchMessage(&msg);
+
+    } /* End Main loop */
+
+    msg_Dbg( p_event->obj, "Win32 Vout EventThread terminating" );
+
+    Win32VoutCloseWindow( p_event );
+    vlc_restorecancel(canc);
+    return NULL;
+}
+
+struct event_thread_t *EventThreadCreate( vlc_object_t *obj, vlc_window_t *parent_window,
+                                   const struct vout_display_placement *display,
+                                   const vout_display_owner_t *owner )
+{
+    if (parent_window->type != VLC_WINDOW_TYPE_HWND)
+        return NULL;
+     /* Create the Vout EventThread, this thread is created by us to isolate
+     * the Win32 PeekMessage function calls. We want to do this because
+     * Windows can stay blocked inside this call for a long time, and when
+     * this happens it thus blocks vlc's video_output thread.
+     * Vout EventThread will take care of the creation of the video
+     * window (because PeekMessage has to be called from the same thread which
+     * created the window). */
+    msg_Dbg( obj, "creating Vout EventThread" );
+    struct event_thread_t *p_event = malloc( sizeof(*p_event) );
+    if( !p_event )
+        return NULL;
+
+    p_event->obj = obj;
+    vlc_mutex_init( &p_event->lock );
+    vlc_cond_init( &p_event->wait );
+    atomic_init( &p_event->b_done, false );
+    p_event->b_ready = false;
+    p_event->b_error = false;
+
+    p_event->parent_window = parent_window;
+
+    _snwprintf( p_event->class_video, ARRAY_SIZE(p_event->class_video),
+                TEXT("VLC video output %p"), (void *)p_event );
+
+#ifdef HAVE_WIN32_SENSORS
+    p_event->init_move = owner;
+    p_event->p_sensors = NULL;
+#else
+    VLC_UNUSED(owner);
+#endif
+    p_event->init_width  = display->width;
+    p_event->init_height = display->height;
+
+    if( vlc_clone( &p_event->thread, EventThread, p_event ) )
+    {
+        msg_Err( obj, "cannot create Vout EventThread" );
+        free(p_event);
+        return NULL;
+    }
+
+    vlc_mutex_lock( &p_event->lock );
+    while( !p_event->b_ready )
+        vlc_cond_wait( &p_event->wait, &p_event->lock );
+    const bool b_error = p_event->b_error;
+    vlc_mutex_unlock( &p_event->lock );
+
+    if( b_error )
+    {
+        vlc_join( p_event->thread, NULL );
+        free(p_event);
+        return NULL;
+    }
+
+#ifdef HAVE_WIN32_SENSORS
+    if (owner != NULL)
+        p_event->p_sensors = HookWindowsSensors(vlc_object_logger(obj), owner, p_event->hvideownd);
+#endif
+    msg_Dbg( obj, "Vout EventThread running" );
+
+    return p_event;
+}
+
+void EventThreadUpdateSize( struct event_thread_t *p_event )
 {
     RECT clientRect;
     GetClientRect(p_event->hparent, &clientRect);


=====================================
modules/video_output/win32/events.h
=====================================
@@ -27,17 +27,9 @@
 /**
  * HWNDs manager.
  */
-typedef struct event_thread_t event_thread_t;
-
-typedef struct {
-    bool is_projected;
-    unsigned width;
-    unsigned height;
-} event_cfg_t;
-
-event_thread_t *EventThreadCreate( vlc_object_t *, vlc_window_t *);
-void            EventThreadDestroy( event_thread_t * );
-int             EventThreadStart( event_thread_t *, const event_cfg_t * );
-HWND            EventThreadVideoHWND( const event_thread_t * );
-void            EventThreadStop( event_thread_t * );
-void            EventThreadUpdateSize( event_thread_t * );
+struct event_thread_t *EventThreadCreate( vlc_object_t *, vlc_window_t *,
+                                   const struct vout_display_placement *,
+                                   const vout_display_owner_t * );
+void            EventThreadDestroy( struct event_thread_t * );
+HWND            EventThreadVideoHWND( const struct event_thread_t * );
+void            EventThreadUpdateSize( struct event_thread_t * );


=====================================
modules/video_output/win32/glwin32.c
=====================================
@@ -66,9 +66,6 @@ typedef struct vout_display_sys_t
 
     vlc_gl_t              *gl;
     vout_display_opengl_t *vgl;
-
-    /* Sensors */
-    void *p_sensors;
 } vout_display_sys_t;
 
 static void           Prepare(vout_display_t *, picture_t *, subpicture_t *, vlc_tick_t);
@@ -137,9 +134,6 @@ static int Open(vout_display_t *vd,
         goto error;
     CommonPlacePicture(vd, &sys->area);
 
-    if (vd->source->projection_mode != PROJECTION_MODE_RECTANGULAR)
-        sys->p_sensors = HookWindowsSensors(vd, CommonVideoHWND(&sys->area));
-
     vlc_window_SetTitle(vd->cfg->window, VOUT_TITLE " (OpenGL output)");
 
     vout_display_cfg_t embed_cfg = *vd->cfg;
@@ -200,7 +194,6 @@ static void Close(vout_display_t *vd)
         vlc_object_delete(surface);
     }
 
-    UnhookWindowsSensors(sys->p_sensors);
     CommonWindowClean(&sys->area);
 
     free(sys);


=====================================
modules/video_output/win32/meson.build
=====================================
@@ -5,6 +5,7 @@
 # Direct3D11 video output
 d3d11_sources = files('direct3d11.cpp', 'd3d11_quad.cpp', 'd3d11_scaler.cpp', 'd3d11_shaders.cpp', 'd3d_shaders.c', 'd3d_dynamic_shader.c', 'common.c')
 d3d11_link_with = [ d3d11_common_lib ]
+d3d11_cargs = []
 d3d11_deps = []
 if get_option('winstore_app')
     d3d11_deps += [
@@ -14,12 +15,17 @@ if get_option('winstore_app')
 else
     d3d11_sources += files('d3d11_swapchain.cpp', 'dxgi_swapchain.cpp', 'events.c', 'sensors.cpp', 'win32touch.c')
     d3d11_link_with += [ chroma_copy_lib ]
+    d3d11_cargs += '-DHAVE_WIN32_SENSORS'
+    d3d11_deps += [
+        cc.find_library('user32')
+    ]
 endif
 
 vlc_modules += {
     'name' : 'direct3d11',
     'sources' : d3d11_sources,
     'link_with' : d3d11_link_with,
+    'c_args' : d3d11_cargs,
     'dependencies' : d3d11_deps
 }
 
@@ -28,7 +34,10 @@ if have_win_desktop
     vlc_modules += {
         'name' : 'direct3d9',
         'sources' : files('direct3d9.c', 'common.c', 'events.c', 'sensors.cpp', 'win32touch.c'),
-        'link_with' : [ d3d9_common_lib, chroma_copy_lib ]
+        'link_with' : [ d3d9_common_lib, chroma_copy_lib ],
+        'dependencies' : [
+            cc.find_library('user32')
+        ]
     }
 
     # GDI video output
@@ -36,6 +45,9 @@ if have_win_desktop
         'name' : 'wingdi',
         'sources' : files('wingdi.c', 'common.c', 'events.c', 'win32touch.c'),
         'link_with' : [ chroma_copy_lib ]
+        'dependencies' : [
+            cc.find_library('user32')
+        ]
     }
 
     opengl32_lib = cc.find_library('opengl32', required: false)
@@ -47,8 +59,10 @@ if have_win_desktop
                 files('glwin32.c', 'common.c', 'events.c', 'sensors.cpp', 'win32touch.c'),
                 opengl_vout_commonsources
             ],
-            'c_args' : [ contrib_inc_args ],
-            'dependencies' : [ gl_common_dep, opengl32_lib ]
+            'c_args' : [ contrib_inc_args, '-DHAVE_WIN32_SENSORS' ],
+            'dependencies' : [ gl_common_dep, opengl32_lib,
+                cc.find_library('user32')
+            ]
         }
 
         # WGL


=====================================
modules/video_output/win32/sensors.cpp
=====================================
@@ -26,7 +26,7 @@
 #endif
 
 #include "events.h"
-#include "common.h"
+#include "sensors.h"
 
 #include <initguid.h>
 #include <wrl/client.h>
@@ -41,8 +41,8 @@ using Microsoft::WRL::ComPtr;
 class SensorReceiver : public ISensorEvents
 {
 public:
-    SensorReceiver(vout_display_t *vd, const vlc_viewpoint_t & init_viewpoint)
-        :vd(vd)
+    SensorReceiver(const vout_display_owner_t *o, const vlc_viewpoint_t & init_viewpoint)
+        :owner(*o)
         ,current_pos(init_viewpoint)
     {}
 
@@ -128,7 +128,8 @@ public:
             old_pos.roll  - current_pos.roll,
             0.0f
         };
-        vout_display_SendEventViewpointMoved(vd, &vp);
+        if (owner.viewpoint_moved)
+            owner.viewpoint_moved(owner.sys, &vp);
         return S_OK;
     }
 
@@ -147,12 +148,12 @@ public:
     }
 
 private:
-    vout_display_t *const vd;
+    vout_display_owner_t owner;
     vlc_viewpoint_t current_pos;
     long m_cRef;
 };
 
-void *HookWindowsSensors(vout_display_t *vd, HWND hwnd)
+void *HookWindowsSensors(vlc_logger *vd, const vout_display_owner_t *move, HWND hwnd)
 {
     ComPtr<ISensorManager> pSensorManager;
     HRESULT hr = CoCreateInstance( __uuidof(SensorManager),
@@ -165,13 +166,13 @@ void *HookWindowsSensors(vout_display_t *vd, HWND hwnd)
     hr = pSensorManager->GetSensorsByType(SENSOR_TYPE_INCLINOMETER_3D, &pInclinometers);
     if (FAILED(hr))
     {
-        msg_Dbg(vd, "inclinometer not found. (hr=0x%lX)", hr);
+        vlc_debug(vd, "inclinometer not found. (hr=0x%lX)", hr);
         return NULL;
     }
 
     ULONG count;
     pInclinometers->GetCount(&count);
-    msg_Dbg(vd, "Found %lu inclinometer", count);
+    vlc_debug(vd, "Found %lu inclinometer", count);
     for (ULONG i=0; i<count; ++i)
     {
         ComPtr<ISensor> pSensor;
@@ -213,7 +214,7 @@ void *HookWindowsSensors(vout_display_t *vd, HWND hwnd)
             PropVariantClear(&pvRot);
         }
 
-        SensorReceiver *received = new(std::nothrow) SensorReceiver(vd, start_viewpoint);
+        SensorReceiver *received = new(std::nothrow) SensorReceiver(move, start_viewpoint);
         if (received)
         {
             pSensor->SetEventSink(received);


=====================================
modules/video_output/win32/sensors.h
=====================================
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * sensors.h: Windows sensor handling
+ *****************************************************************************
+ * Copyright © 2017 Steve Lhomme
+ * Copyright © 2017 VideoLabs
+ *
+ * Authors: Steve Lhomme <robux4 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+
+#ifndef VLC_WIN32_COMMON_SENSOR_H
+#define VLC_WIN32_COMMON_SENSOR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void* HookWindowsSensors(struct vlc_logger *, const vout_display_owner_t *, HWND);
+void UnhookWindowsSensors(void*);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif // VLC_WIN32_COMMON_SENSOR_H


=====================================
modules/video_output/win32/win32touch.c
=====================================
@@ -31,45 +31,34 @@
 
 #include <assert.h>
 
-static BOOL DecodeGestureAction( vlc_object_t *p_this, win32_gesture_sys_t *p_gesture, const GESTUREINFO* p_gi );
-static BOOL DecodeGestureProjection( vlc_object_t *p_this, win32_gesture_sys_t *p_gesture, const GESTUREINFO* p_gi );
+enum {
+    GESTURE_ACTION_UNDEFINED = 0,
+    GESTURE_ACTION_VOLUME,
+    GESTURE_ACTION_JUMP,
+    GESTURE_ACTION_BRIGHTNESS
+};
 
-LRESULT DecodeGesture( vlc_object_t *p_this, win32_gesture_sys_t *p_gesture,
-                       HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
+
+struct win32_gesture_sys_t
 {
-    if( !p_gesture )
-        return DefWindowProc( hWnd, message, wParam, lParam );
+    DWORD       i_type;                 /* Gesture ID */
+    int         i_action;               /* GESTURE_ACTION */
 
-    GESTUREINFO gi;
-    ZeroMemory( &gi, sizeof( GESTUREINFO ) );
-    gi.cbSize = sizeof( GESTUREINFO );
+    int         i_beginx;               /* Start X position */
+    int         i_beginy;               /* Start Y position */
+    int         i_lasty;                /* Last known Y position for PAN */
+    double      f_lastzoom;             /* Last zoom factor */
 
-    BOOL bResult  = p_gesture->OurGetGestureInfo((HGESTUREINFO)lParam, &gi);
-    BOOL bHandled = FALSE; /* Needed to release the handle */
+    ULONGLONG   i_ullArguments;         /* Base values to compare between 2 zoom gestures */
+    bool        b_2fingers;             /* Did we detect 2 fingers? */
 
-    if( bResult )
-        bHandled = p_gesture->DecodeGestureImpl(p_this, p_gesture, &gi);
-    else
-    {
-        DWORD dwErr = GetLastError();
-        if( dwErr > 0 )
-            msg_Err( p_this, "Could not retrieve a valid GESTUREINFO structure" );
-    }
+    bool (*DecodeGestureImpl)( vlc_object_t *, struct win32_gesture_sys_t *, const GESTUREINFO* );
+};
 
-    if( bHandled )
-    {
-        /* Close the Handle, if we handled the gesture, a contrario
-         * from the doc example */
-        p_gesture->OurCloseGestureInfoHandle((HGESTUREINFO)lParam);
-        return 0;
-    }
-    else
-        return DefWindowProc( hWnd, message, wParam, lParam );
-}
 
-static BOOL DecodeGestureAction( vlc_object_t *p_this, win32_gesture_sys_t *p_gesture, const GESTUREINFO* p_gi )
+static bool DecodeGestureAction( vlc_object_t *p_this, struct win32_gesture_sys_t *p_gesture, const GESTUREINFO* p_gi )
 {
-    BOOL bHandled = FALSE; /* Needed to release the handle */
+    bool bHandled = false; /* Needed to release the handle */
     switch ( p_gi->dwID )
     {
         case GID_BEGIN:
@@ -107,7 +96,7 @@ static BOOL DecodeGestureAction( vlc_object_t *p_this, win32_gesture_sys_t *p_ge
             break;
         case GID_PAN:
             p_gesture->i_type = GID_PAN;
-            bHandled = TRUE;
+            bHandled = true;
 
             if (p_gi->dwFlags & GF_BEGIN) {
                 p_gesture->i_beginx = p_gi->ptsLocation.x;
@@ -166,7 +155,7 @@ static BOOL DecodeGestureAction( vlc_object_t *p_this, win32_gesture_sys_t *p_ge
         case GID_TWOFINGERTAP:
             p_gesture->i_type = GID_TWOFINGERTAP;
             var_SetInteger( vlc_object_instance(p_this), "key-action", ACTIONID_PLAY_PAUSE );
-            bHandled = TRUE;
+            bHandled = true;
             break;
         case GID_ZOOM:
             p_gesture->i_type = GID_ZOOM;
@@ -190,10 +179,10 @@ static BOOL DecodeGestureAction( vlc_object_t *p_this, win32_gesture_sys_t *p_ge
                 default:
                     msg_Err( p_this, "Unmanaged dwFlag: %lx", p_gi->dwFlags );
             }
-            bHandled = TRUE;
+            bHandled = true;
             break;
         case WM_VSCROLL:
-            bHandled = TRUE;
+            bHandled = true;
             break;
         default:
             break;
@@ -202,11 +191,11 @@ static BOOL DecodeGestureAction( vlc_object_t *p_this, win32_gesture_sys_t *p_ge
 }
 
 
-static BOOL DecodeGestureProjection( vlc_object_t *p_this, win32_gesture_sys_t *p_gesture, const GESTUREINFO* p_gi )
+static bool DecodeGestureProjection( vlc_object_t *p_this, struct win32_gesture_sys_t *p_gesture, const GESTUREINFO* p_gi )
 {
     //vout_display_t *vd = (vout_display_t *)p_this;
 
-    BOOL bHandled = FALSE; /* Needed to release the handle */
+    bool bHandled = false; /* Needed to release the handle */
     switch ( p_gi->dwID )
     {
         case GID_BEGIN:
@@ -238,7 +227,7 @@ static BOOL DecodeGestureProjection( vlc_object_t *p_this, win32_gesture_sys_t *
         case GID_PAN:
             //vd->cfg->display.width;
             p_gesture->i_type = GID_PAN;
-            bHandled = TRUE;
+            bHandled = true;
             if (p_gi->dwFlags & GF_BEGIN) {
                 p_gesture->i_beginx = p_gi->ptsLocation.x;
                 p_gesture->i_beginy = p_gi->ptsLocation.y;
@@ -277,11 +266,11 @@ static BOOL DecodeGestureProjection( vlc_object_t *p_this, win32_gesture_sys_t *
         case GID_TWOFINGERTAP:
             p_gesture->i_type = GID_TWOFINGERTAP;
             var_SetInteger( vlc_object_instance(p_this), "key-action", ACTIONID_PLAY_PAUSE );
-            bHandled = TRUE;
+            bHandled = true;
             break;
         case GID_ZOOM:
             p_gesture->i_type = GID_ZOOM;
-            bHandled = TRUE;
+            bHandled = true;
             switch( p_gi->dwFlags )
             {
                 case GF_BEGIN:
@@ -308,7 +297,7 @@ static BOOL DecodeGestureProjection( vlc_object_t *p_this, win32_gesture_sys_t *
             }
             break;
         case WM_VSCROLL:
-            bHandled = TRUE;
+            bHandled = true;
             break;
         default:
             break;
@@ -316,7 +305,37 @@ static BOOL DecodeGestureProjection( vlc_object_t *p_this, win32_gesture_sys_t *
     return bHandled;
 }
 
-BOOL InitGestures( HWND hwnd, win32_gesture_sys_t **pp_gesture, bool b_isProjected )
+bool DecodeGesture( vlc_object_t *p_this, struct win32_gesture_sys_t *p_gesture,
+                    HGESTUREINFO hGestureInfo )
+{
+    if( !p_gesture )
+        return false;
+
+    GESTUREINFO gi;
+    ZeroMemory( &gi, sizeof( GESTUREINFO ) );
+    gi.cbSize = sizeof( GESTUREINFO );
+
+    if( GetGestureInfo(hGestureInfo, &gi) )
+    {
+        if( p_gesture->DecodeGestureImpl(p_this, p_gesture, &gi) )
+        {
+            /* Close the Handle, if we handled the gesture, a contrario
+             * from the doc example */
+            CloseGestureInfoHandle(hGestureInfo);
+            return true;
+        }
+    }
+    else
+    {
+        DWORD dwErr = GetLastError();
+        if( dwErr > 0 )
+            msg_Err( p_this, "Could not retrieve a valid GESTUREINFO structure" );
+    }
+
+    return false;
+}
+
+struct win32_gesture_sys_t *InitGestures( HWND hwnd, bool b_isProjected )
 {
     BOOL result = FALSE;
     GESTURECONFIG config = { 0, 0, 0 };
@@ -337,37 +356,21 @@ BOOL InitGestures( HWND hwnd, win32_gesture_sys_t **pp_gesture, bool b_isProject
         config.dwBlock = GC_PAN_WITH_INERTIA;
     }
 
-    win32_gesture_sys_t *p_gesture = malloc( sizeof(win32_gesture_sys_t) );
-    if( !p_gesture )
-    {
-        *pp_gesture = NULL;
-        return FALSE;
-    }
-
-    HINSTANCE h_user32_dll = LoadLibrary(TEXT("user32.dll"));
-    if( !h_user32_dll )
-    {
-        *pp_gesture = NULL;
-        free( p_gesture );
-        return FALSE;
-    }
-
-    BOOL (WINAPI *OurSetGestureConfig) (HWND, DWORD, UINT, PGESTURECONFIG, UINT);
-    OurSetGestureConfig = (void *)GetProcAddress(h_user32_dll, "SetGestureConfig");
-
-    p_gesture->OurCloseGestureInfoHandle =
-        (void *)GetProcAddress(h_user32_dll, "CloseGestureInfoHandle" );
-    p_gesture->OurGetGestureInfo =
-        (void *)GetProcAddress(h_user32_dll, "GetGestureInfo");
-    if( OurSetGestureConfig )
+    struct win32_gesture_sys_t *p_gesture = malloc( sizeof(*p_gesture) );
+    if( unlikely(!p_gesture) )
+        return NULL;
+
+    result = SetGestureConfig(
+            hwnd,
+            0,
+            1,
+            &config,
+            sizeof( GESTURECONFIG )
+            );
+    if (result == 0)
     {
-        result = OurSetGestureConfig(
-                hwnd,
-                0,
-                1,
-                &config,
-                sizeof( GESTURECONFIG )
-                );
+        free(p_gesture);
+        return NULL;
     }
     if (b_isProjected)
         p_gesture->DecodeGestureImpl = DecodeGestureProjection;
@@ -379,15 +382,11 @@ BOOL InitGestures( HWND hwnd, win32_gesture_sys_t **pp_gesture, bool b_isProject
     p_gesture->i_action   = GESTURE_ACTION_UNDEFINED;
     p_gesture->i_beginx   = p_gesture->i_beginy = -1;
     p_gesture->i_lasty    = -1;
-    p_gesture->huser_dll  = h_user32_dll;
 
-    *pp_gesture = p_gesture;
-    return result;
+    return p_gesture;
 }
 
-void CloseGestures( win32_gesture_sys_t *p_gesture )
+void CloseGestures( struct win32_gesture_sys_t *p_gesture )
 {
-    if (p_gesture && p_gesture->huser_dll )
-        FreeLibrary( p_gesture->huser_dll );
     free( p_gesture );
 }


=====================================
modules/video_output/win32/win32touch.h
=====================================
@@ -41,40 +41,13 @@
 extern "C" {
 #endif
 
-enum {
-    GESTURE_ACTION_UNDEFINED = 0,
-    GESTURE_ACTION_VOLUME,
-    GESTURE_ACTION_JUMP,
-    GESTURE_ACTION_BRIGHTNESS
-};
+struct win32_gesture_sys_t;
 
+struct win32_gesture_sys_t *InitGestures( HWND hwnd, bool b_isProjected );
 
-typedef struct win32_gesture_sys_t {
-    DWORD       i_type;                 /* Gesture ID */
-    int         i_action;               /* GESTURE_ACTION */
+bool DecodeGesture( vlc_object_t *, struct win32_gesture_sys_t *, HGESTUREINFO );
 
-    int         i_beginx;               /* Start X position */
-    int         i_beginy;               /* Start Y position */
-    int         i_lasty;                /* Last known Y position for PAN */
-    double      f_lastzoom;             /* Last zoom factor */
-
-    ULONGLONG   i_ullArguments;         /* Base values to compare between 2 zoom gestures */
-    bool        b_2fingers;             /* Did we detect 2 fingers? */
-
-    BOOL (*DecodeGestureImpl)( vlc_object_t *p_this, struct win32_gesture_sys_t *p_gesture, const GESTUREINFO* p_gi );
-
-    HINSTANCE   huser_dll;              /* user32.dll */
-    BOOL (WINAPI * OurCloseGestureInfoHandle)(HGESTUREINFO hGestureInfo);
-    BOOL (WINAPI * OurGetGestureInfo)(HGESTUREINFO hGestureInfo, PGESTUREINFO pGestureInfo);
-} win32_gesture_sys_t;
-
-
-BOOL InitGestures( HWND hwnd, win32_gesture_sys_t **p_gesture, bool b_isProjected );
-
-LRESULT DecodeGesture( vlc_object_t *p_intf, win32_gesture_sys_t *p_gesture,
-        HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
-
-void CloseGestures( win32_gesture_sys_t *p_gesture );
+void CloseGestures( struct win32_gesture_sys_t * );
 
 #ifdef __cplusplus
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/47486d9992c3c58a929ec535b2da59ecc325a367...fb094900f294be5fede5539a26fdf4d3c0058449

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/47486d9992c3c58a929ec535b2da59ecc325a367...fb094900f294be5fede5539a26fdf4d3c0058449
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list