command: make window-scale property observable

Add a generic mechanism to the VO to relay "extra" events from VO to
player. Use it to notify the core of window resizes, which in turn will
be used to mark all affected properties ("window-scale" in this case) as
changed.

(I refrained from hacking this as internal command into input_ctx, or to
poll the state change, etc. - but in the end, maybe it would be best to
actually pass the client API context directly to the places where events
can happen.)
This commit is contained in:
wm4 2014-11-02 20:26:51 +01:00
parent 61b06f3756
commit 4e2574f025
15 changed files with 64 additions and 4 deletions

View File

@ -620,7 +620,7 @@ int mpv_request_event(mpv_handle *ctx, mpv_event_id event, int enable)
{
if (!mpv_event_name(event) || enable < 0 || enable > 1)
return MPV_ERROR_INVALID_PARAMETER;
assert(event < INTERNAL_EVENT_BASE); // excluded above; they have no name
assert(event < (int)INTERNAL_EVENT_BASE); // excluded above; they have no name
pthread_mutex_lock(&ctx->lock);
uint64_t bit = 1ULL << event;
ctx->event_mask = enable ? ctx->event_mask | bit : ctx->event_mask & ~bit;

View File

@ -3201,6 +3201,7 @@ static const char *const *const mp_event_property_change[] = {
E(MPV_EVENT_CHAPTER_CHANGE, "chapter", "chapter-metadata"),
E(MP_EVENT_CACHE_UPDATE, "cache", "cache-free", "cache-used", "cache-idle",
"demuxer-cache-duration", "demuxer-cache-idle"),
E(MP_EVENT_WIN_RESIZE, "window-scale"),
};
#undef E

View File

@ -39,9 +39,13 @@ void mp_notify_property(struct MPContext *mpctx, const char *property);
int mp_get_property_id(const char *name);
uint64_t mp_get_property_event_mask(const char *name);
// Must start with the first unused positive value in enum mpv_event_id
#define INTERNAL_EVENT_BASE 24
#define MP_EVENT_CACHE_UPDATE (INTERNAL_EVENT_BASE + 0)
enum {
// Must start with the first unused positive value in enum mpv_event_id
// MPV_EVENT_* and MP_EVENT_* must not overlap.
INTERNAL_EVENT_BASE = 24,
MP_EVENT_CACHE_UPDATE,
MP_EVENT_WIN_RESIZE,
};
bool mp_hook_test_completion(struct MPContext *mpctx, char *type);
void mp_hook_run(struct MPContext *mpctx, char *client, char *type);

View File

@ -670,6 +670,14 @@ static void handle_cursor_autohide(struct MPContext *mpctx)
mpctx->mouse_cursor_visible = mouse_cursor_visible;
}
static void handle_vo_events(struct MPContext *mpctx)
{
struct vo *vo = mpctx->video_out;
int events = vo ? vo_query_events(vo, VO_EVENTS_USER, true) : 0;
if (events & VO_EVENT_RESIZE)
mp_notify(mpctx, MP_EVENT_WIN_RESIZE, NULL);
}
void add_frame_pts(struct MPContext *mpctx, double pts)
{
if (pts == MP_NOPTS_VALUE || mpctx->hrseek_framedrop) {
@ -884,6 +892,7 @@ void run_playloop(struct MPContext *mpctx)
}
handle_cursor_autohide(mpctx);
handle_vo_events(mpctx);
handle_heartbeat_cmd(mpctx);
fill_audio_out_buffers(mpctx, endpts);
@ -995,6 +1004,7 @@ void mp_idle(struct MPContext *mpctx)
mpctx->sleeptime = 100.0;
mp_process_input(mpctx);
handle_cursor_autohide(mpctx);
handle_vo_events(mpctx);
update_osd_msg(mpctx);
handle_osd_redraw(mpctx);
}

View File

@ -129,6 +129,7 @@ struct vo_internal {
bool request_redraw; // redraw request from player to VO
bool want_redraw; // redraw request from VO to player
bool paused;
int queued_events;
int64_t flip_queue_offset; // queue flip events at most this much in advance
@ -838,6 +839,31 @@ int64_t vo_get_vsync_interval(struct vo *vo)
return vo->in->vsync_interval;
}
// Set specific event flags, and wakeup the playback core if needed.
// vo_query_events() can retrieve the events again.
void vo_event(struct vo *vo, int event)
{
struct vo_internal *in = vo->in;
pthread_mutex_lock(&in->lock);
if ((in->queued_events & event & VO_EVENTS_USER) != (event & VO_EVENTS_USER))
mp_input_wakeup(vo->input_ctx);
in->queued_events |= event;
pthread_mutex_unlock(&in->lock);
}
// Check event flags set with vo_event(). Return the mask of events that was
// set and included in the events parameter. If clear==true, clear these events.
int vo_query_events(struct vo *vo, int events, bool clear)
{
struct vo_internal *in = vo->in;
pthread_mutex_lock(&in->lock);
int r = in->queued_events & events;
if (clear)
in->queued_events &= ~(unsigned)r;
pthread_mutex_unlock(&in->lock);
return r;
}
/**
* \brief lookup an integer in a table, table must have 0 as the last key
* \param key key to search for

View File

@ -30,10 +30,16 @@
#include "common/common.h"
#include "options/options.h"
// VO needs to redraw
#define VO_EVENT_EXPOSE 1
// VO needs to update state to a new window size
#define VO_EVENT_RESIZE 2
// The ICC profile needs to be reloaded
#define VO_EVENT_ICC_PROFILE_PATH_CHANGED 4
// Set of events the player core may be interested in.
#define VO_EVENTS_USER (VO_EVENT_RESIZE)
enum mp_voctrl {
/* signal a device reset seek */
VOCTRL_RESET = 1,
@ -298,6 +304,8 @@ void vo_destroy(struct vo *vo);
void vo_set_paused(struct vo *vo, bool paused);
int64_t vo_get_drop_count(struct vo *vo);
int vo_query_format(struct vo *vo, int format);
void vo_event(struct vo *vo, int event);
int vo_query_events(struct vo *vo, int events, bool clear);
void vo_set_flip_queue_offset(struct vo *vo, int64_t us);
int64_t vo_get_vsync_interval(struct vo *vo);

View File

@ -1267,6 +1267,8 @@ static int control(struct vo *vo, uint32_t request, void *data)
if (events & VO_EVENT_EXPOSE)
vo->want_redraw = true;
vo_event(vo, events);
return r;
}

View File

@ -439,6 +439,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
get_and_update_icc_profile(vo, p->icc_opts);
vo->want_redraw = true;
}
vo_event(vo, events);
mpgl_unlock(p->glctx);
return r;

View File

@ -2161,6 +2161,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
resize(vo, vo->dwidth, vo->dheight);
if (events & VO_EVENT_EXPOSE)
vo->want_redraw = true;
vo_event(vo, events);
return r;
}

View File

@ -561,6 +561,7 @@ static int wait_events(struct vo *vo, int64_t until_time_us)
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
check_resize(vo);
vo_event(vo, VO_EVENT_RESIZE);
break;
}
break;

View File

@ -567,6 +567,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
resize(p);
if (events & VO_EVENT_EXPOSE)
vo->want_redraw = true;
vo_event(vo, events);
return r;
}

View File

@ -1114,6 +1114,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
} else if (events & VO_EVENT_EXPOSE) {
vo->want_redraw = true;
}
vo_event(vo, events);
return r;
}

View File

@ -705,6 +705,8 @@ static int control(struct vo *vo, uint32_t request, void *data)
if (events & VO_EVENT_RESIZE)
resize(p);
vo_event(vo, events);
return r;
}

View File

@ -631,6 +631,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
int r = vo_x11_control(vo, &events, request, data);
if (events & (VO_EVENT_EXPOSE | VO_EVENT_RESIZE))
resize(vo);
vo_event(vo, events);
return r;
}

View File

@ -851,6 +851,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
int r = vo_x11_control(vo, &events, request, data);
if (events & (VO_EVENT_EXPOSE | VO_EVENT_RESIZE))
resize(vo);
vo_event(vo, events);
return r;
}