Commit 5bea1844 authored by Laurent Aimar's avatar Laurent Aimar

Allowed vout display events to be issued from anywhere.

For lack of vout display currently doing it (obviously ;), it is
untested.
parent 03a5ec2b
......@@ -207,8 +207,10 @@ struct vout_display_owner_t {
* be overwritten nor used directly (use the vout_display_SendEvent*
* wrapper.
*
* You can send it at any time i.e. from any vout_display_t functions
* (TODO add support from a private thread).
* You can send it at any time i.e. from any vout_display_t functions or
* from another thread.
* Becarefull, it does not ensure correct serialization if it is used
* from multiple threads.
*/
void (*event)(vout_display_t *, int, va_list);
......
......@@ -275,19 +275,6 @@ struct vout_display_owner_sys_t {
bool is_wrapper; /* Is the current display a wrapper */
vout_display_t *wrapper; /* Vout display wrapper */
/* mouse state */
struct {
vlc_mouse_t state;
mtime_t last_pressed;
mtime_t last_moved;
bool is_hidden;
/* */
mtime_t double_click_timeout;
mtime_t hide_timeout;
} mouse;
/* */
vout_display_cfg_t cfg;
bool is_on_top_initial;
......@@ -306,16 +293,6 @@ struct vout_display_owner_sys_t {
} crop_saved;
/* */
bool reset_pictures;
bool ch_fullscreen;
bool is_fullscreen;
bool ch_display_size;
int display_width;
int display_height;
bool display_is_fullscreen;
bool ch_display_filled;
bool is_display_filled;
......@@ -347,6 +324,34 @@ struct vout_display_owner_sys_t {
/* */
video_format_t source;
filter_chain_t *filters;
/* Lock protecting the variables used by
* VoutDisplayEvent(ie vout_display_SendEvent) */
vlc_mutex_t lock;
/* mouse state */
struct {
vlc_mouse_t state;
mtime_t last_pressed;
mtime_t last_moved;
bool is_hidden;
bool ch_activity;
/* */
mtime_t double_click_timeout;
mtime_t hide_timeout;
} mouse;
bool reset_pictures;
bool ch_fullscreen;
bool is_fullscreen;
bool ch_display_size;
int display_width;
int display_height;
bool display_is_fullscreen;
};
static void VoutDisplayCreateRender(vout_display_t *vd)
......@@ -426,6 +431,8 @@ static void VoutDisplayEventMouse(vout_display_t *vd, int event, va_list args)
{
vout_display_owner_sys_t *osys = vd->owner.sys;
vlc_mutex_lock(&osys->lock);
/* */
vlc_mouse_t m = osys->mouse.state;
bool is_ignored = false;
......@@ -487,8 +494,10 @@ static void VoutDisplayEventMouse(vout_display_t *vd, int event, va_list args)
assert(0);
}
if (is_ignored)
if (is_ignored) {
vlc_mutex_unlock(&osys->lock);
return;
}
/* Emulate double-click if needed */
if (!vd->info.has_double_click &&
......@@ -507,10 +516,13 @@ static void VoutDisplayEventMouse(vout_display_t *vd, int event, va_list args)
osys->mouse.state = m;
/* */
osys->mouse.is_hidden = false;
osys->mouse.ch_activity = true;
if (!vd->info.has_hide_mouse)
osys->mouse.last_moved = mdate();
/* */
vlc_mutex_unlock(&osys->lock);
/* */
vout_SendEventMouseVisible(osys->vout);
vout_SendDisplayEventMouse(osys->vout, &m);
......@@ -545,10 +557,12 @@ static void VoutDisplayEvent(vout_display_t *vd, int event, va_list args)
msg_Dbg(vd, "VoutDisplayEvent 'fullscreen' %d", is_fullscreen);
if (!is_fullscreen == !osys->is_fullscreen)
break;
osys->ch_fullscreen = true;
osys->is_fullscreen = is_fullscreen;
vlc_mutex_lock(&osys->lock);
if (!is_fullscreen != !osys->is_fullscreen) {
osys->ch_fullscreen = true;
osys->is_fullscreen = is_fullscreen;
}
vlc_mutex_unlock(&osys->lock);
break;
}
......@@ -560,10 +574,14 @@ static void VoutDisplayEvent(vout_display_t *vd, int event, va_list args)
width, height, is_fullscreen ? "fullscreen" : "window");
/* */
vlc_mutex_lock(&osys->lock);
osys->ch_display_size = true;
osys->display_width = width;
osys->display_height = height;
osys->display_is_fullscreen = is_fullscreen;
vlc_mutex_unlock(&osys->lock);
break;
}
......@@ -572,7 +590,10 @@ static void VoutDisplayEvent(vout_display_t *vd, int event, va_list args)
/* */
assert(vd->info.has_pictures_invalid);
vlc_mutex_lock(&osys->lock);
osys->reset_pictures = true;
vlc_mutex_unlock(&osys->lock);
break;
}
default:
......@@ -603,22 +624,50 @@ void vout_ManageDisplay(vout_display_t *vd)
/* Handle mouse timeout */
const mtime_t date = mdate();
bool hide_mouse = false;
vlc_mutex_lock(&osys->lock);
if (!osys->mouse.is_hidden &&
osys->mouse.last_moved + osys->mouse.hide_timeout < date) {
osys->mouse.is_hidden = hide_mouse = true;
} else if (osys->mouse.ch_activity) {
osys->mouse.is_hidden = false;
}
osys->mouse.ch_activity = false;
vlc_mutex_unlock(&osys->lock);
if (hide_mouse) {
if (!vd->info.has_hide_mouse) {
msg_Dbg(vd, "auto hidding mouse");
vout_display_Control(vd, VOUT_DISPLAY_HIDE_MOUSE);
}
osys->mouse.is_hidden = true;
vout_SendEventMouseHidden(osys->vout);
}
bool reset_pictures = false;
bool reset_render = false;
for (;;) {
if (!osys->ch_fullscreen &&
!osys->ch_display_size &&
!osys->reset_pictures &&
vlc_mutex_lock(&osys->lock);
bool ch_fullscreen = osys->ch_fullscreen;
bool is_fullscreen = osys->is_fullscreen;
osys->ch_fullscreen = false;
bool ch_display_size = osys->ch_display_size;
int display_width = osys->display_width;
int display_height = osys->display_height;
bool display_is_fullscreen = osys->display_is_fullscreen;
osys->ch_display_size = false;
bool reset_pictures = osys->reset_pictures;
osys->reset_pictures = false;
vlc_mutex_unlock(&osys->lock);
if (!ch_fullscreen &&
!ch_display_size &&
!reset_pictures &&
!osys->ch_display_filled &&
!osys->ch_zoom &&
!osys->ch_on_top &&
......@@ -627,47 +676,45 @@ void vout_ManageDisplay(vout_display_t *vd)
break;
/* */
if (osys->ch_fullscreen) {
if (ch_fullscreen) {
vout_display_cfg_t cfg = osys->cfg;
cfg.is_fullscreen = osys->is_fullscreen;
cfg.is_fullscreen = is_fullscreen;
cfg.display.width = cfg.is_fullscreen ? 0 : osys->width_saved;
cfg.display.height = cfg.is_fullscreen ? 0 : osys->height_saved;
if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_FULLSCREEN, &cfg)) {
msg_Err(vd, "Failed to set fullscreen");
osys->is_fullscreen = osys->cfg.is_fullscreen;
is_fullscreen = osys->cfg.is_fullscreen;
}
osys->cfg.is_fullscreen = osys->is_fullscreen;
osys->ch_fullscreen = false;
osys->cfg.is_fullscreen = is_fullscreen;
/* */
vout_SendEventFullscreen(osys->vout, osys->cfg.is_fullscreen);
}
/* */
if (osys->ch_display_size) {
if (ch_display_size) {
vout_display_cfg_t cfg = osys->cfg;
cfg.display.width = osys->display_width;
cfg.display.height = osys->display_height;
cfg.display.width = display_width;
cfg.display.height = display_height;
if (!cfg.is_fullscreen != !osys->display_is_fullscreen ||
if (!cfg.is_fullscreen != !display_is_fullscreen ||
vout_display_Control(vd, VOUT_DISPLAY_CHANGE_DISPLAY_SIZE, &cfg)) {
if (!cfg.is_fullscreen == !osys->display_is_fullscreen)
if (!cfg.is_fullscreen == !display_is_fullscreen)
msg_Err(vd, "Failed to resize display");
/* We ignore the resized */
osys->display_width = osys->cfg.display.width;
osys->display_height = osys->cfg.display.height;
display_width = osys->cfg.display.width;
display_height = osys->cfg.display.height;
}
osys->cfg.display.width = osys->display_width;
osys->cfg.display.height = osys->display_height;
osys->cfg.display.width = display_width;
osys->cfg.display.height = display_height;
if (!osys->display_is_fullscreen) {
osys->width_saved = osys->display_width;
osys->height_saved = osys->display_height;
if (!display_is_fullscreen) {
osys->width_saved = display_width;
osys->height_saved = display_height;
}
osys->ch_display_size = false;
}
/* */
if (osys->ch_display_filled) {
......@@ -824,17 +871,15 @@ void vout_ManageDisplay(vout_display_t *vd)
}
/* */
if (osys->reset_pictures) {
if (reset_pictures) {
if (vout_display_Control(vd, VOUT_DISPLAY_RESET_PICTURES)) {
/* FIXME what to do here ? */
msg_Err(vd, "Failed to reset pictures (probably fatal)");
}
reset_pictures = true;
osys->reset_pictures = false;
reset_render = true;
}
}
if (reset_pictures)
if (reset_render)
VoutDisplayResetRender(vd);
}
......@@ -842,7 +887,11 @@ bool vout_AreDisplayPicturesInvalid(vout_display_t *vd)
{
vout_display_owner_sys_t *osys = vd->owner.sys;
return osys->reset_pictures;
vlc_mutex_lock(&osys->lock);
const bool reset_pictures = osys->reset_pictures;
vlc_mutex_unlock(&osys->lock);
return reset_pictures;
}
bool vout_IsDisplayFiltered(vout_display_t *vd)
......@@ -864,10 +913,12 @@ void vout_SetDisplayFullscreen(vout_display_t *vd, bool is_fullscreen)
{
vout_display_owner_sys_t *osys = vd->owner.sys;
vlc_mutex_lock(&osys->lock);
if (!osys->is_fullscreen != !is_fullscreen) {
osys->ch_fullscreen = true;
osys->is_fullscreen = is_fullscreen;
}
vlc_mutex_unlock(&osys->lock);
}
void vout_SetDisplayFilled(vout_display_t *vd, bool is_filled)
......@@ -954,6 +1005,8 @@ static vout_display_t *DisplayNew(vout_thread_t *vout,
osys->is_wrapper = is_wrapper;
osys->wrapper = wrapper;
vlc_mutex_init(&osys->lock);
vlc_mouse_Init(&osys->mouse.state);
osys->mouse.last_moved = mdate();
osys->mouse.double_click_timeout = double_click_timeout;
......@@ -1039,6 +1092,7 @@ void vout_DeleteDisplay(vout_display_t *vd, vout_display_state_t *state)
if (osys->is_wrapper)
SplitterClose(vd);
vout_display_Delete(vd);
vlc_mutex_destroy(&osys->lock);
free(osys);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment