0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

cocoa: make live-resizing as fast as before

Interrupt video timing. This means the Cocoa event loop does not have
to up to 2 video frame durations until redrawing the frame finally has
finished.

We abuse the VO event flags for this. Eventually this should use
wait_vo() or so in the video timing wait function, but for now the
interaction this would require with the code of other VOs/backends
would cause too much of a mess.
This commit is contained in:
wm4 2015-05-12 22:31:22 +02:00
parent 7735b29732
commit 29eb764fe0
3 changed files with 14 additions and 9 deletions

View File

@ -629,13 +629,15 @@ static void vo_cocoa_resize_redraw(struct vo *vo, int width, int height)
s->frame_w = s->frame_h = 0;
s->pending_events |= VO_EVENT_RESIZE | VO_EVENT_EXPOSE;
vo_wakeup(vo);
vo_event(vo, VO_EVENT_LIVE_RESIZING);
while (s->frame_w != width && s->frame_h != height && s->vo_ready) {
if (pthread_cond_timedwait(&s->resize_wakeup, &s->resize_lock, &e))
break;
}
vo_query_and_reset_events(vo, VO_EVENT_LIVE_RESIZING);
pthread_mutex_unlock(&s->resize_lock);
}

View File

@ -484,7 +484,7 @@ static void wakeup_locked(struct vo *vo)
{
struct vo_internal *in = vo->in;
pthread_cond_signal(&in->wakeup);
pthread_cond_broadcast(&in->wakeup);
if (vo->event_fd >= 0)
wakeup_event_fd(vo);
if (vo->driver->wakeup)
@ -567,14 +567,14 @@ static void wait_until(struct vo *vo, int64_t target)
{
struct vo_internal *in = vo->in;
struct timespec ts = mp_time_us_to_timespec(target);
while (1) {
int64_t now = mp_time_us();
if (target <= now)
pthread_mutex_lock(&in->lock);
while (target > mp_time_us()) {
if (in->queued_events & VO_EVENT_LIVE_RESIZING)
break;
if (pthread_cond_timedwait(&in->wakeup, &in->lock, &ts))
break;
pthread_mutex_lock(&in->lock);
pthread_cond_timedwait(&in->wakeup, &in->lock, &ts);
pthread_mutex_unlock(&in->lock);
}
pthread_mutex_unlock(&in->lock);
}
// needs lock
@ -722,7 +722,7 @@ static bool render_frame(struct vo *vo)
in->request_redraw = false;
}
pthread_cond_signal(&in->wakeup); // for vo_wait_frame()
pthread_cond_broadcast(&in->wakeup); // for vo_wait_frame()
mp_input_wakeup(vo->input_ctx);
pthread_mutex_unlock(&in->lock);
@ -984,6 +984,7 @@ void vo_event(struct vo *vo, int event)
mp_input_wakeup(vo->input_ctx);
in->queued_events |= event;
in->internal_events |= event;
wakeup_locked(vo);
pthread_mutex_unlock(&in->lock);
}

View File

@ -40,6 +40,8 @@
#define VO_EVENT_WIN_STATE 8
// The ambient light conditions changed and need to be reloaded
#define VO_EVENT_AMBIENT_LIGHTING_CHANGED 16
// Special mechanism for making resizing with Cocoa react faster
#define VO_EVENT_LIVE_RESIZING 32
// Set of events the player core may be interested in.
#define VO_EVENTS_USER (VO_EVENT_RESIZE | VO_EVENT_WIN_STATE)