@@ -393,6 +393,7 @@ static bool display_gl_process_key(struct state_gl *s, long long int key);
393393static bool display_gl_reconfigure (void * state , struct video_desc desc );
394394static void gl_draw (double ratio , double bottom_offset , bool double_buf );
395395static void gl_change_aspect (struct state_gl * s , int width , int height );
396+ static void gl_present_current_frame (struct state_gl * s );
396397static void gl_resize (GLFWwindow * win , int width , int height );
397398static void gl_render_glsl (struct state_gl * s , char * data );
398399static void gl_reconfigure_screen (struct state_gl * s , struct video_desc desc );
@@ -1162,6 +1163,10 @@ static void gl_reconfigure_screen(struct state_gl *s, struct video_desc desc)
11621163{
11631164 assert (s -> magic == MAGIC_GL );
11641165
1166+ // see note for display_gl_render_last()
1167+ vf_free (s -> current_frame );
1168+ s -> current_frame = nullptr ;
1169+
11651170 s -> dxt_height = desc .color_spec == DXT1 || desc .color_spec == DXT1_YUV || desc .color_spec == DXT5 ?
11661171 (desc .height + 3 ) / 4 * 4 : desc .height ;
11671172
@@ -1296,9 +1301,6 @@ static void gl_reconfigure_screen(struct state_gl *s, struct video_desc desc)
12961301 }
12971302 }
12981303
1299- vf_free (s -> current_frame );
1300- s -> current_frame = nullptr ;
1301-
13021304 s -> scratchpad = realloc (s -> scratchpad , desc .width * desc .height * 8 );
13031305 s -> current_display_desc = desc ;
13041306}
@@ -1426,18 +1428,27 @@ gl_process_frames(struct state_gl *s)
14261428 gl_reconfigure_screen (s , video_desc_from_frame (frame ));
14271429 }
14281430
1429- CHK_PTHR (pthread_mutex_lock (& s -> lock ));
1430- if (s -> current_frame ) {
1431+ if (s -> current_frame ) { // recycle old "current" frame
14311432 if (s -> paused ) {
14321433 SWAP_PTR (frame , s -> current_frame );
14331434 }
14341435 vf_recycle (s -> current_frame );
1435- simple_linked_list_append (s -> free_frame_queue ,
1436- s -> current_frame );
1436+ CHK_PTHR (pthread_mutex_lock (& s -> lock ));
1437+ {
1438+ simple_linked_list_append (s -> free_frame_queue ,
1439+ s -> current_frame );
1440+ }
1441+ CHK_PTHR (pthread_mutex_unlock (& s -> lock ));
14371442 }
14381443 s -> current_frame = frame ;
1439- CHK_PTHR (pthread_mutex_unlock (& s -> lock ));
14401444
1445+ gl_present_current_frame (s );
1446+ }
1447+
1448+ static void
1449+ gl_present_current_frame (struct state_gl * s )
1450+ {
1451+ struct video_frame * frame = s -> current_frame ;
14411452 glBindTexture (GL_TEXTURE_2D , s -> texture_display );
14421453
14431454 gl_render (s , frame -> tiles [0 ].data );
@@ -1628,17 +1639,21 @@ display_gl_print_depth(GLFWmonitor *monitor)
16281639 return mode -> redBits ;
16291640}
16301641
1642+ /**
1643+ * Set as glfwSetWindowRefreshCallback() - called whe needing to redraw screen.
1644+ * In this module it is useful to redraw if no data is coming to keep the
1645+ * contents when user resizes the win or so.
1646+ * @note
1647+ * this callback may be called also from some GLFW calls called in
1648+ * gl_reconfigure_screen() so it is important that s->current_frame == nullptr
1649+ * during reconfigure
1650+ */
16311651static void display_gl_render_last (GLFWwindow * win ) {
16321652 struct state_gl * s = glfwGetWindowUserPointer (win );
1633- CHK_PTHR (pthread_mutex_lock (& s -> lock ));
1634- struct video_frame * f = s -> current_frame ;
1635- s -> current_frame = nullptr ;
1636- CHK_PTHR (pthread_mutex_unlock (& s -> lock ));
1637- if (!f ) {
1638- return ;
1653+ if (s -> current_frame != nullptr ) {
1654+ // redraw last frame
1655+ gl_present_current_frame (s );
16391656 }
1640- // redraw last frame
1641- display_gl_putf (s , f , PUTF_NONBLOCK );
16421657}
16431658
16441659#if defined GLEW_VERSION
0 commit comments