@@ -366,6 +366,15 @@ static void display_task(void *arg)
366366 if (msg .type == RG_TASK_MSG_STOP )
367367 break ;
368368
369+ const rg_surface_t * update = msg .dataPtr ;
370+
371+ if (display .source .width != update -> width || display .source .height != update -> height )
372+ {
373+ display .source .width = update -> width ;
374+ display .source .height = update -> height ;
375+ display .changed = true;
376+ }
377+
369378 if (display .changed )
370379 {
371380 update_viewport_scaling ();
@@ -380,7 +389,7 @@ static void display_task(void *arg)
380389 display .changed = false;
381390 }
382391
383- write_update (msg . dataPtr );
392+ write_update (update );
384393 // draw_on_screen_display(0, display.screen.height);
385394 rg_task_receive (& msg , -1 );
386395
@@ -393,7 +402,9 @@ void rg_display_force_redraw(void)
393402 display .changed = true;
394403 // memset(screen_line_checksum, 0, sizeof(screen_line_checksum));
395404 rg_system_event (RG_EVENT_REDRAW , NULL );
396- rg_display_sync (true);
405+ // Wait for the redraw to be complete, if any was initiated!
406+ while (rg_display_is_busy ())
407+ rg_task_yield ();
397408}
398409
399410const rg_display_t * rg_display_get_info (void )
@@ -509,25 +520,20 @@ void rg_display_submit(const rg_surface_t *update, uint32_t flags)
509520 if (!update || !update -> data )
510521 return ;
511522
512- if (display .source .width != update -> width || display .source .height != update -> height )
513- {
514- rg_display_sync (true);
515- display .source .width = update -> width ;
516- display .source .height = update -> height ;
517- display .changed = true;
518- }
519-
520523 rg_task_send (display_task_queue , & (rg_task_msg_t ){.dataPtr = update }, -1 );
521524
522525 counters .blockTime += rg_system_timer () - time_start ;
523526 counters .totalFrames ++ ;
524527}
525528
526- bool rg_display_sync ( bool block )
529+ bool rg_display_is_busy ( void )
527530{
528- while (block && rg_task_messages_waiting (display_task_queue ))
529- continue ; // We should probably yield?
530- return !rg_task_messages_waiting (display_task_queue );
531+ return rg_task_messages_waiting (display_task_queue ) != 0 ;
532+ }
533+
534+ void rg_display_sync (void )
535+ {
536+ lcd_sync ();
531537}
532538
533539// FIXME: We need to add a way to group writes and indicate completion, so that the display driver will blit/flip only
@@ -550,8 +556,11 @@ void rg_display_write_rect(int left, int top, int width, int height, int stride,
550556 // This will work for now because we rarely draw from different threads (so all we need is ensure
551557 // that we're not interrupting a display update). But what we SHOULD be doing is acquire a lock
552558 // before every call to lcd_set_window and release it only after the last call to lcd_send_buffer.
553- if (!(flags & RG_DISPLAY_WRITE_NOSYNC ))
554- rg_display_sync (true);
559+ if ((flags & RG_DISPLAY_WRITE_NOSYNC ) == 0 )
560+ {
561+ while (rg_display_is_busy ())
562+ rg_task_yield ();
563+ }
555564
556565 // This isn't really necessary but it makes sense to invalidate
557566 // the lines we're about to overwrite...
@@ -666,9 +675,10 @@ bool rg_display_set_geometry(int width, int height, const rg_margins_t *margins)
666675 // update_viewport_scaling(); // This will be implicitly done by the display task
667676 rg_gui_update_geometry (); // Let the GUI know that the geometry has changed
668677 rg_system_event (RG_EVENT_GEOMETRY , 0 ); // Let everybody know that the geometry has changed
669- RG_LOGI ("Screen: resolution=%dx%d, effective=%dx%d, format=%d" ,
670- display .screen .real_width , display .screen .real_height ,
671- display .screen .width , display .screen .height , display .screen .format );
678+ RG_LOGI ("Screen: resolution=%dx%d (eff. %dx%d), margins=(%d %d %d %d), format=%d" ,
679+ display .screen .real_width , display .screen .real_height , display .screen .width , display .screen .height ,
680+ display .screen .margins .left , display .screen .margins .top , display .screen .margins .right , display .screen .margins .bottom ,
681+ display .screen .format );
672682 return true;
673683}
674684
0 commit comments