Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 6f61189f rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Passing the window to the SDL thread, but nothing is displaying

parent 15b7d97b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!57Resolve "SDL2 module"
...@@ -36,6 +36,7 @@ struct module_sdl2_window { ...@@ -36,6 +36,7 @@ struct module_sdl2_window {
pthread_mutex_t mtx; pthread_mutex_t mtx;
struct lkt_thread self; struct lkt_thread self;
volatile int launched; volatile int launched;
volatile int mpv_wakeup;
}; };
/* Thread related functions */ /* Thread related functions */
...@@ -51,8 +52,8 @@ sdl_thread__(struct lkt_thread_arg *arg) ...@@ -51,8 +52,8 @@ sdl_thread__(struct lkt_thread_arg *arg)
int w, h; int w, h;
free(arg); free(arg);
(void) self; (void) self;
if (sdl2 == NULL) RETURN_UNLESS(sdl2, "Big nope here, the sdl window pointer is NULL", NULL);
return false; fprintf(stderr, " * Started SDL thread\n");
/* SDL events won't change the database, only the mpv one's will. /* SDL events won't change the database, only the mpv one's will.
Do this to be able to put the SDL stuff inside a thread and don't change Do this to be able to put the SDL stuff inside a thread and don't change
...@@ -96,6 +97,8 @@ loop: ...@@ -96,6 +97,8 @@ loop:
flags = mpv_render_context_update(sdl2->mpv_gl); flags = mpv_render_context_update(sdl2->mpv_gl);
if (flags & MPV_RENDER_UPDATE_FRAME) if (flags & MPV_RENDER_UPDATE_FRAME)
redraw = 1; redraw = 1;
if (event.type == wakeup_on_mpv_events)
sdl2->mpv_wakeup = 1;
} }
/* Handle mpv events are not done here. */ /* Handle mpv events are not done here. */
} }
...@@ -217,8 +220,8 @@ module_sdl2_new(struct lkt_win *const win) ...@@ -217,8 +220,8 @@ module_sdl2_new(struct lkt_win *const win)
if (sdl2 == NULL) { if (sdl2 == NULL) {
sdl2 = calloc(1, sizeof(struct module_sdl2_window)); sdl2 = calloc(1, sizeof(struct module_sdl2_window));
memset(sdl2, 0, sizeof(struct module_sdl2_window));
RETURN_UNLESS(sdl2, "Out of memory", false); RETURN_UNLESS(sdl2, "Out of memory", false);
memset(sdl2, 0, sizeof(struct module_sdl2_window));
/* Yeah, this is how it is done. */ /* Yeah, this is how it is done. */
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
...@@ -259,19 +262,21 @@ module_sdl2_new(struct lkt_win *const win) ...@@ -259,19 +262,21 @@ module_sdl2_new(struct lkt_win *const win)
/* Init mpv_gl here */ /* Init mpv_gl here */
RETURN_IF(init_mpv_gl__(sdl2->mpv, &sdl2->mpv_gl, params), "Failed to init mpv_gl", false); RETURN_IF(init_mpv_gl__(sdl2->mpv, &sdl2->mpv_gl, params), "Failed to init mpv_gl", false);
/* Finish */
SDL_SetWindowTitle(sdl2->window, "Lektord");
SDL_DisableScreenSaver();
win->window = sdl2;
/* Start the SDL thread */ /* Start the SDL thread */
if (!sdl2->launched) { if (!sdl2->launched) {
struct lkt_thread_arg *arg = calloc(1, sizeof(struct lkt_thread_arg)); struct lkt_thread_arg *arg = calloc(1, sizeof(struct lkt_thread_arg));
RETURN_UNLESS(arg, "Out of memory", false); RETURN_UNLESS(arg, "Out of memory", false);
arg->args = win; arg->args = win;
sdl2->launched = 1;
RETURN_IF(lkt_th_new(&sdl2->self, LKT_DEFAULT_LIST_SIZE, sdl_thread__, arg), RETURN_IF(lkt_th_new(&sdl2->self, LKT_DEFAULT_LIST_SIZE, sdl_thread__, arg),
"Failed to launch the SDL thread", false); "Failed to launch the SDL thread", false);
} }
/* Finish */
SDL_SetWindowTitle(sdl2->window, "Lektord");
SDL_DisableScreenSaver();
win->window = sdl2;
return true; return true;
} }
...@@ -338,7 +343,12 @@ module_sdl2_handle_events(struct lkt_win *const win, sqlite3 *db, enum mpd_idle_ ...@@ -338,7 +343,12 @@ module_sdl2_handle_events(struct lkt_win *const win, sqlite3 *db, enum mpd_idle_
{ {
struct module_sdl2_window *sdl2 = win->window; struct module_sdl2_window *sdl2 = win->window;
RETURN_UNLESS(sdl2, "Can't handle events from a NULL window", false); RETURN_UNLESS(sdl2, "Can't handle events from a NULL window", false);
return ! lmpv_handle(win, sdl2->mpv, db, mpd_idle_events, if (sdl2->mpv_wakeup) {
(int *) &sdl2->mpv_time_pos, sdl2->mpv_wakeup = 0;
(int *) &sdl2->mpv_duration); return ! lmpv_handle(win, sdl2->mpv, db, mpd_idle_events,
(int *) &sdl2->mpv_time_pos,
(int *) &sdl2->mpv_duration);
}
else
return true;
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter