diff options
author | nerdopolis <bluescreen_avenger@verizon.net> | 2023-12-13 19:05:59 -0500 |
---|---|---|
committer | n3rdopolis <bluescreenavenger@gmail.com> | 2023-12-16 13:25:01 +0000 |
commit | 815d3c72e2e4f7299490e43147972e7d31b91d17 (patch) | |
tree | cbc9b70729cd3202ca11fd974da7e0271eede46b | |
parent | 0083c97ffa2a7c6914bfa35a0cd38899e67e79ea (diff) |
ply-pixel-display: Pause the display and unpause it at a framerate
-rw-r--r-- | src/libply-splash-core/ply-pixel-display.c | 31 | ||||
-rw-r--r-- | src/libply-splash-graphics/ply-console-viewer.c | 2 |
2 files changed, 31 insertions, 2 deletions
diff --git a/src/libply-splash-core/ply-pixel-display.c b/src/libply-splash-core/ply-pixel-display.c index 62398038..6de4b1a0 100644 --- a/src/libply-splash-core/ply-pixel-display.c +++ b/src/libply-splash-core/ply-pixel-display.c @@ -41,6 +41,10 @@ #include "ply-renderer.h" #include "ply-utils.h" +#ifndef FRAMES_PER_SECOND +#define FRAMES_PER_SECOND 60 +#endif + struct _ply_pixel_display { ply_event_loop_t *loop; @@ -58,6 +62,23 @@ struct _ply_pixel_display int pause_count; }; +static void +on_timeout (ply_pixel_display_t *display) +{ + double sleep_time; + + + sleep_time = 1.0 / FRAMES_PER_SECOND; + + ply_pixel_display_unpause_updates (display); + ply_pixel_display_pause_updates (display); + + ply_event_loop_watch_for_timeout (display->loop, + sleep_time, + (ply_event_loop_timeout_handler_t) + on_timeout, display); +} + ply_pixel_display_t * ply_pixel_display_new (ply_renderer_t *renderer, ply_renderer_head_t *head) @@ -182,9 +203,19 @@ ply_pixel_display_set_draw_handler (ply_pixel_display_t *display, ply_pixel_display_draw_handler_t draw_handler, void *user_data) { + double sleep_time; + assert (display != NULL); display->draw_handler = draw_handler; display->draw_handler_user_data = user_data; + + sleep_time = 1.0 / FRAMES_PER_SECOND; + + ply_event_loop_watch_for_timeout (display->loop, + sleep_time, + (ply_event_loop_timeout_handler_t) + on_timeout, display); + ply_pixel_display_pause_updates (display); } diff --git a/src/libply-splash-graphics/ply-console-viewer.c b/src/libply-splash-graphics/ply-console-viewer.c index 8e1ee628..e423cc40 100644 --- a/src/libply-splash-graphics/ply-console-viewer.c +++ b/src/libply-splash-graphics/ply-console-viewer.c @@ -158,7 +158,6 @@ update_console_messages (ply_console_viewer_t *console_viewer) if (number_of_messages < 0) return; - ply_pixel_display_pause_updates (console_viewer->display); node = ply_list_get_first_node (console_viewer->message_labels); while (node != NULL) { ply_rich_text_t *line = NULL; @@ -211,7 +210,6 @@ update_console_messages (ply_console_viewer_t *console_viewer) ply_pixel_display_draw_area (console_viewer->display, 0, 0, ply_pixel_display_get_width (console_viewer->display), ply_pixel_display_get_height (console_viewer->display)); - ply_pixel_display_unpause_updates (console_viewer->display); } void |