summaryrefslogtreecommitdiff
path: root/modules/sdl2
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-07-06 20:56:57 +0200
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-07-06 20:56:57 +0200
commitd2a391c693c0b1bcd9c5eda132f51be7991db189 (patch)
tree11d820634cbf05762b74a60868ce9c0394317867 /modules/sdl2
parente28fb4cd650441d8e429b59d75113875cec40337 (diff)
sdl2: check events from main thread
this fixes a segfault on MacOSX. can be tested with video-loop: $ baresip -mcairo.so -msdl2.so -e/vidloop
Diffstat (limited to 'modules/sdl2')
-rw-r--r--modules/sdl2/sdl.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/modules/sdl2/sdl.c b/modules/sdl2/sdl.c
index 9b3f27e..8a036e5 100644
--- a/modules/sdl2/sdl.c
+++ b/modules/sdl2/sdl.c
@@ -25,12 +25,17 @@ struct vidisp_st {
struct vidsz size; /**< Current size */
enum vidfmt fmt; /**< Current pixel format */
bool fullscreen; /**< Fullscreen flag */
+ struct tmr tmr;
+ Uint32 flags;
};
static struct vidisp *vid;
+static void event_handler(void *arg);
+
+
static uint32_t match_fmt(enum vidfmt fmt)
{
switch (fmt) {
@@ -76,10 +81,14 @@ static void sdl_reset(struct vidisp_st *st)
}
-static void handle_events(struct vidisp_st *st)
+static void event_handler(void *arg)
{
+ struct vidisp_st *st = arg;
SDL_Event event;
+ tmr_start(&st->tmr, 100, event_handler, st);
+
+ /* NOTE: events must be checked from main thread */
while (SDL_PollEvent(&event)) {
if (event.type == SDL_KEYDOWN) {
@@ -91,7 +100,13 @@ static void handle_events(struct vidisp_st *st)
st->fullscreen = !st->fullscreen;
info("sdl: %sable fullscreen mode\n",
st->fullscreen ? "en" : "dis");
- sdl_reset(st);
+
+ if (st->fullscreen)
+ st->flags |= SDL_WINDOW_FULLSCREEN;
+ else
+ st->flags &= ~SDL_WINDOW_FULLSCREEN;
+
+ SDL_SetWindowFullscreen(st->window, st->flags);
break;
default:
@@ -106,6 +121,7 @@ static void destructor(void *arg)
{
struct vidisp_st *st = arg;
+ tmr_cancel(&st->tmr);
sdl_reset(st);
}
@@ -132,6 +148,8 @@ static int alloc(struct vidisp_st **stp, const struct vidisp *vd,
st->vd = vd;
+ tmr_start(&st->tmr, 100, event_handler, st);
+
if (err)
mem_deref(st);
else
@@ -172,11 +190,12 @@ static int display(struct vidisp_st *st, const char *title,
}
if (!st->window) {
- Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_FOCUS;
char capt[256];
+ st->flags = SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_FOCUS;
+
if (st->fullscreen)
- flags |= SDL_WINDOW_FULLSCREEN;
+ st->flags |= SDL_WINDOW_FULLSCREEN;
if (title) {
re_snprintf(capt, sizeof(capt), "%s - %u x %u",
@@ -191,7 +210,7 @@ static int display(struct vidisp_st *st, const char *title,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
frame->size.w, frame->size.h,
- flags);
+ st->flags);
if (!st->window) {
warning("sdl: unable to create sdl window: %s\n",
SDL_GetError());
@@ -272,8 +291,6 @@ static int display(struct vidisp_st *st, const char *title,
/* Update the screen! */
SDL_RenderPresent(st->renderer);
- handle_events(st);
-
return 0;
}