Discussion:
[vlc-commits] window: add enable/disable callbacks
Rémi Denis-Courmont
2018-12-08 14:50:29 UTC
Permalink
vlc | branch: master | Rémi Denis-Courmont <***@remlab.net> | Sat Dec 1 22:43:23 2018 +0200| [59a049d4a1cb63be65a7d8bf6b808e68389242af] | committer: Rémi Denis-Courmont

window: add enable/disable callbacks

The window provider should remain available even when no video is shown
so that available fullscreen targets can be tracked (or whatever other
events from the display server).

This is similar to audio output existing even without an audio stream.
http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=59a049d4a1cb63be65a7d8bf6b808e68389242af
---

include/vlc_vout_window.h | 25 ++++++++++++++
modules/gui/macosx/VLCVideoOutputProvider.m | 2 ++
modules/gui/minimal_macosx/intf.m | 2 ++
modules/gui/qt/main_interface.cpp | 2 ++
modules/gui/skins2/src/skin_main.cpp | 2 ++
src/libvlccore.sym | 2 ++
src/video_output/opengl.c | 5 +++
src/video_output/window.c | 52 +++++++++++++++++++++++------
8 files changed, 81 insertions(+), 11 deletions(-)

diff --git a/include/vlc_vout_window.h b/include/vlc_vout_window.h
index a3857c80fa..dbfb1be43e 100644
--- a/include/vlc_vout_window.h
+++ b/include/vlc_vout_window.h
@@ -134,6 +134,8 @@ struct vout_window_callbacks {
};

struct vout_window_operations {
+ int (*enable)(vout_window_t *, const vout_window_cfg_t *);
+ void (*disable)(vout_window_t *);
void (*resize)(vout_window_t *, unsigned width, unsigned height);

/**
@@ -294,6 +296,29 @@ static inline void vout_window_UnsetFullScreen(vout_window_t *window)
}

/**
+ * Enables a window.
+ *
+ * This informs the window provider that the window is about to be taken into
+ * active use. A window is always initially disabled. This is so that the
+ * window provider can provide a persistent connection to the display server,
+ * and track any useful events, such as monitors hotplug.
+ *
+ * The window handle (vout_window_t.handle) and display (vout_window_t.display)
+ * must remain valid and constant while the window is enabled.
+ */
+int vout_window_Enable(vout_window_t *window, const vout_window_cfg_t *cfg);
+
+/**
+ * Disables a window.
+ *
+ * This informs the window provider that the window is no longer needed.
+ *
+ * Note that the window may be re-enabled later by a call to
+ * vout_window_Enable().
+ */
+void vout_window_Disable(vout_window_t *window);
+
+/**
* Report current window size
*
* This notifies the user of the window what the pixel dimensions of the
diff --git a/modules/gui/macosx/VLCVideoOutputProvider.m b/modules/gui/macosx/VLCVideoOutputProvider.m
index cf065d33c7..66d7141575 100644
--- a/modules/gui/macosx/VLCVideoOutputProvider.m
+++ b/modules/gui/macosx/VLCVideoOutputProvider.m
@@ -113,6 +113,8 @@ static atomic_bool b_intf_starting = ATOMIC_VAR_INIT(false);
static void WindowClose(vout_window_t *);

static const struct vout_window_operations ops = {
+ NULL,
+ NULL,
WindowResize,
WindowClose,
WindowSetState,
diff --git a/modules/gui/minimal_macosx/intf.m b/modules/gui/minimal_macosx/intf.m
index 3778313f56..72c1b25eb2 100644
--- a/modules/gui/minimal_macosx/intf.m
+++ b/modules/gui/minimal_macosx/intf.m
@@ -148,6 +148,8 @@ static void WindowSetFullscreen(vout_window_t *p_wnd, const char *psz_id)
static void WindowClose(vout_window_t *);

static const struct vout_window_operations ops = {
+ NULL,
+ NULL,
WindowResize,
WindowClose,
WindowSetState,
diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index da0e8bdeb7..cd279b6610 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -731,6 +731,8 @@ bool MainInterface::getVideo( struct vout_window_t *p_wnd,
bool fullscreen )
{
static const struct vout_window_operations ops = {
+ NULL,
+ NULL,
MainInterface::resizeVideo,
MainInterface::releaseVideo,
MainInterface::requestVideoState,
diff --git a/modules/gui/skins2/src/skin_main.cpp b/modules/gui/skins2/src/skin_main.cpp
index 8af14b4471..0265ac5565 100644
--- a/modules/gui/skins2/src/skin_main.cpp
+++ b/modules/gui/skins2/src/skin_main.cpp
@@ -393,6 +393,8 @@ static void WindowSetFullscreen( vout_window_t *pWnd, const char * )
}

static const struct vout_window_operations window_ops = {
+ NULL,
+ NULL,
WindowResize,
WindowClose,
WindowSetState,
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 9423e2fc20..d53f6b27c1 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -746,6 +746,8 @@ vout_OSDSlider
vout_OSDText
vout_window_New
vout_window_Delete
+vout_window_Enable
+vout_window_Disable
vout_display_GetDefaultDisplaySize
vout_display_PlacePicture
vout_display_SendMouseMovedDisplayCoordinates
diff --git a/src/video_output/opengl.c b/src/video_output/opengl.c
index e737667710..b0ceb02119 100644
--- a/src/video_output/opengl.c
+++ b/src/video_output/opengl.c
@@ -147,6 +147,10 @@ vlc_gl_t *vlc_gl_surface_Create(vlc_object_t *obj,
free(modlist);
if (surface == NULL)
goto error;
+ if (vout_window_Enable(surface, cfg)) {
+ vout_window_Delete(surface);
+ goto error;
+ }
if (wp != NULL)
*wp = surface;

@@ -202,6 +206,7 @@ void vlc_gl_surface_Destroy(vlc_gl_t *gl)
vlc_gl_surface_t *sys = surface->owner.sys;

vlc_gl_Release(gl);
+ vout_window_Disable(surface);
vout_window_Delete(surface);
vlc_mutex_destroy(&sys->lock);
free(sys);
diff --git a/src/video_output/window.c b/src/video_output/window.c
index bf8db2b24e..772968c545 100644
--- a/src/video_output/window.c
+++ b/src/video_output/window.c
@@ -78,28 +78,49 @@ vout_window_t *vout_window_New(vlc_object_t *obj, const char *module,
if (var_InheritBool(obj, "disable-screensaver") &&
(window->type == VOUT_WINDOW_TYPE_XID || window->type == VOUT_WINDOW_TYPE_HWND
|| window->type == VOUT_WINDOW_TYPE_WAYLAND))
- {
- w->inhibit = vlc_inhibit_Create(VLC_OBJECT (window));
- if (w->inhibit != NULL)
- vlc_inhibit_Set(w->inhibit, VLC_INHIBIT_VIDEO);
- }
+ w->inhibit = vlc_inhibit_Create(VLC_OBJECT(window));
else
w->inhibit = NULL;
return window;
}

+int vout_window_Enable(vout_window_t *window,
+ const vout_window_cfg_t *restrict cfg)
+{
+ window_t *w = container_of(window, window_t, wnd);
+
+ if (window->ops->enable != NULL) {
+ int err = window->ops->enable(window, cfg);
+ if (err)
+ return err;
+ }
+
+ if (w->inhibit != NULL)
+ vlc_inhibit_Set(w->inhibit, VLC_INHIBIT_VIDEO);
+
+ return VLC_SUCCESS;
+}
+
+void vout_window_Disable(vout_window_t *window)
+{
+ window_t *w = container_of(window, window_t, wnd);
+
+ if (w->inhibit != NULL)
+ vlc_inhibit_Set(w->inhibit, VLC_INHIBIT_NONE);
+
+ if (window->ops->disable != NULL)
+ window->ops->disable(window);
+}
+
void vout_window_Delete(vout_window_t *window)
{
if (!window)
return;

- window_t *w = (window_t *)window;
- if (w->inhibit)
- {
- vlc_inhibit_Set (w->inhibit, VLC_INHIBIT_NONE);
- vlc_inhibit_Destroy (w->inhibit);
- }
+ window_t *w = container_of(window, window_t, wnd);

+ if (w->inhibit != NULL)
+ vlc_inhibit_Destroy(w->inhibit);
if (window->ops->destroy != NULL)
window->ops->destroy(window);
vlc_objres_clear(VLC_OBJECT(window));
@@ -375,6 +396,14 @@ vout_window_t *vout_display_window_New(vout_thread_t *vout,

window = vout_window_New((vlc_object_t *)vout, modlist, cfg, &owner);
free(modlist);
+
+ if (window != NULL) {
+ if (vout_window_Enable(window, cfg)) {
+ vout_window_Delete(window);
+ window = NULL;
+ }
+ }
+
if (window == NULL)
free(state);
return window;
@@ -401,6 +430,7 @@ void vout_display_window_Delete(vout_window_t *window)
vout_thread_t *vout = (vout_thread_t *)(window->obj.parent);
vout_display_window_t *state = window->owner.sys;

+ vout_window_Disable(window);
vout_window_Delete(window);
var_Destroy(vout, "window-fullscreen-output");
var_Destroy(vout, "window-fullscreen");

Loading...