[psplash,RFC,09/14] Rework flip as function pointer

Message ID 20220425075954.10427-10-vasyl.vavrychuk@opensynergy.com
State New
Headers show
Series Implement DRM backend | expand

Commit Message

Vasyl Vavrychuk April 25, 2022, 7:59 a.m. UTC
It allows making parse_command and psplash_main independent of FB.

Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
---
 psplash-draw.h |  3 +++
 psplash-fb.c   |  8 +++++---
 psplash-fb.h   |  3 ---
 psplash.c      | 16 ++++++++--------
 4 files changed, 16 insertions(+), 14 deletions(-)

Patch

diff --git a/psplash-draw.h b/psplash-draw.h
index 44546b0..292ddd9 100644
--- a/psplash-draw.h
+++ b/psplash-draw.h
@@ -36,6 +36,9 @@  typedef struct PSplashCanvas
   int            green_length;
   int            blue_offset;
   int            blue_length;
+
+  void          *priv;
+  void (*flip)(struct PSplashCanvas *canvas, int sync);
 }
 PSplashCanvas;
 
diff --git a/psplash-fb.c b/psplash-fb.c
index dd50a5a..d41c477 100644
--- a/psplash-fb.c
+++ b/psplash-fb.c
@@ -18,9 +18,10 @@  psplash_wait_for_vsync(PSplashFB *fb)
     fprintf(stderr, "Error, FB vsync ioctl [%d]\n", err);
 }
 
-void
-psplash_fb_flip(PSplashFB *fb, int sync)
+static void
+psplash_fb_flip(PSplashCanvas *canvas, int sync)
 {
+  PSplashFB *fb = canvas->priv;
   char *tmp;
 
   if (fb->double_buffering) {
@@ -154,7 +155,8 @@  psplash_fb_new (int angle, int fbdev_id)
     }
 
   memset (fb, 0, sizeof(PSplashFB));
-
+  fb->canvas.priv = fb;
+  fb->canvas.flip = psplash_fb_flip;
   fb->fd = -1;
 
   if ((fb->fd = open (fbdev, O_RDWR)) < 0)
diff --git a/psplash-fb.h b/psplash-fb.h
index 1b16bd5..979d23a 100644
--- a/psplash-fb.h
+++ b/psplash-fb.h
@@ -40,7 +40,4 @@  psplash_fb_destroy (PSplashFB *fb);
 PSplashFB*
 psplash_fb_new (int angle, int fbdev_id);
 
-void
-psplash_fb_flip(PSplashFB *fb, int sync);
-
 #endif
diff --git a/psplash.c b/psplash.c
index c234d46..036dfb1 100644
--- a/psplash.c
+++ b/psplash.c
@@ -100,7 +100,7 @@  psplash_draw_progress(PSplashCanvas *canvas, int value)
 #endif /* PSPLASH_SHOW_PROGRESS_BAR */
 
 static int
-parse_command (PSplashFB *fb, char *string)
+parse_command(PSplashCanvas *canvas, char *string)
 {
   char *command;
 
@@ -116,7 +116,7 @@  parse_command (PSplashFB *fb, char *string)
       char *arg = strtok(NULL, "\0");
 
       if (arg)
-        psplash_draw_msg(&fb->canvas, arg);
+        psplash_draw_msg(canvas, arg);
     }
  #ifdef PSPLASH_SHOW_PROGRESS_BAR
   else  if (!strcmp(command,"PROGRESS"))
@@ -124,7 +124,7 @@  parse_command (PSplashFB *fb, char *string)
       char *arg = strtok(NULL, "\0");
 
       if (arg)
-        psplash_draw_progress(&fb->canvas, atoi(arg));
+        psplash_draw_progress(canvas, atoi(arg));
     }
 #endif
   else if (!strcmp(command,"QUIT"))
@@ -132,12 +132,12 @@  parse_command (PSplashFB *fb, char *string)
       return 1;
     }
 
-  psplash_fb_flip(fb, 0);
+  canvas->flip(canvas, 0);
   return 0;
 }
 
 void
-psplash_main (PSplashFB *fb, int pipe_fd, int timeout)
+psplash_main(PSplashCanvas *canvas, int pipe_fd, int timeout)
 {
   int            err;
   ssize_t        length = 0;
@@ -200,7 +200,7 @@  psplash_main (PSplashFB *fb, int pipe_fd, int timeout)
 	    continue;
           }
 
-	if (parse_command(fb, cmd))
+	if (parse_command(canvas, cmd))
 	  return;
 
 	length -= cmdlen;
@@ -345,9 +345,9 @@  main (int argc, char** argv)
    * text and progress bar change which overwrite the specific areas with every
    * update.
    */
-  psplash_fb_flip(fb, 1);
+  canvas->flip(canvas, 1);
 
-  psplash_main (fb, pipe_fd, 0);
+  psplash_main(canvas, pipe_fd, 0);
 
   psplash_fb_destroy (fb);