From 20ca62d00fc3ec10c2147dc757929ea5690ddd64 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Fri, 24 Jul 2015 14:24:41 +0200 Subject: [PATCH] GL: fixed slow responsivity --- src/video_display/gl.cpp | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/video_display/gl.cpp b/src/video_display/gl.cpp index ddffdaa35..af642471a 100644 --- a/src/video_display/gl.cpp +++ b/src/video_display/gl.cpp @@ -5,7 +5,7 @@ * @author Martin Pulec */ /* - * Copyright (c) 2010-2014 CESNET, z. s. p. o. + * Copyright (c) 2010-2015 CESNET, z. s. p. o. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -64,6 +64,7 @@ #include #endif /* FREEGLUT */ +#include #include #include #include @@ -189,7 +190,7 @@ struct state_gl { bool paused; bool show_cursor; - bool should_exit_main_loop; + bool should_exit_main_loop; // used only for GLUT (not freeglut) double window_size_factor; @@ -406,6 +407,8 @@ static void display_gl_set_sync_on_vblank(int value) { } else { fprintf(stderr, "[GL display] GLX_SGI_swap_control is presumably not supported. Unable to set sync-on-VBlank.\n"); } +#elif WIN32 + /// @todo #endif } @@ -595,13 +598,8 @@ static void glut_idle_callback(void) } unique_lock lk(s->lock); -#ifdef FREEGLUT - if (s->should_exit_main_loop) { - glutLeaveMainLoop(); - return; - } -#endif - s->new_frame_ready_cv.wait_for(lk, std::chrono::duration(2.0/s->current_display_desc.fps), [s] { + double timeout = min(2.0 / s->current_display_desc.fps, 0.1); + s->new_frame_ready_cv.wait_for(lk, std::chrono::duration(timeout), [s] { return s->frame_queue.size() > 0;}); if (s->frame_queue.size() == 0) { return; @@ -611,6 +609,13 @@ static void glut_idle_callback(void) lk.unlock(); s->frame_consumed_cv.notify_one(); + if (!frame) { +#ifdef FREEGLUT + glutLeaveMainLoop(); +#endif + return; + } + if (s->paused) { unique_lock lk(s->lock); s->free_frame_queue.push(frame); @@ -660,6 +665,9 @@ static void glut_key_callback(unsigned char key, int x, int y) #if defined FREEGLUT || defined HAVE_MACOSX exit_uv(0); #else + /// @todo + /// This shouldn't happen (?). We have either freeglut (Linux, MSW) or + /// original GLUT on OS X glutDestroyWindow(gl->window); exit(1); #endif @@ -792,13 +800,13 @@ void display_gl_run(void *arg) return; } -#if defined HAVE_MACOSX +#if defined FREEGLUT + glutMainLoop(); +#else while (!s->should_exit_main_loop) { glut_idle_callback(); glutCheckLoop(); } -#else /* ! defined HAVE_MACOSX */ - glutMainLoop(); #endif } @@ -1051,8 +1059,12 @@ int display_gl_putf(void *state, struct video_frame *frame, int nonblock) assert(s->magic == MAGIC_GL); std::unique_lock lk(s->lock); + if(!frame) { - s->should_exit_main_loop = true; + s->should_exit_main_loop = true; // used only for GLUT (not freeglut) + s->frame_queue.push(frame); + lk.unlock(); + s->new_frame_ready_cv.notify_one(); return 0; }