Skip to contentSkip to conversation

Support --with-font configure option to use other font headers

PATCH In review Andrei Gherzan 1 participant 4 messages Dec 17, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Support --with-font configure option to use other font headers

From: David Steinberg <[email protected]>

---
 Makefile.am  | 4 ++--
 configure.ac | 6 ++++++
 psplash.c    | 6 +++---
 3 files changed, 11 insertions(+), 5 deletions(-)
Makefile.am +2 -2
index a14152a..3721a6e 100644
@@ -1,11 +1,11 @@
 bin_PROGRAMS=psplash psplash-write
 
-AM_CFLAGS = $(GCC_FLAGS) -D_GNU_SOURCE
+AM_CFLAGS = $(GCC_FLAGS) -D_GNU_SOURCE -DFONT_HEADER=\"$(FONT_NAME)-font.h\" -DFONT_DEF=$(FONT_NAME)_font
 
 psplash_SOURCES = psplash.c psplash.h psplash-fb.c psplash-fb.h \
                   psplash-console.c psplash-console.h           \
 		  psplash-colors.h psplash-config.h		\
-		  psplash-poky-img.h psplash-bar-img.h radeon-font.h
+		  psplash-poky-img.h psplash-bar-img.h $(FONT_NAME)-font.h
 
 psplash_write_SOURCES = psplash-write.c psplash.h
 
configure.ac +6 -0
index 1c4d919..9e78ac0 100644
@@ -14,6 +14,12 @@ fi
 
 AC_SUBST(GCC_FLAGS)
 
+AC_ARG_WITH([font],
+    AS_HELP_STRING([--with-font], [Set font to use (default is 'radeon')]),
+    [FONT_NAME=$withval],
+    [FONT_NAME=radeon])
+AC_SUBST([FONT_NAME])
+
 AC_OUTPUT([
 Makefile
 ])
psplash.c +3 -3
index 992e199..f6442f1 100644
@@ -23,7 +23,7 @@
 #include "psplash-colors.h"
 #include "psplash-poky-img.h"
 #include "psplash-bar-img.h"
-#include "radeon-font.h"
+#include FONT_HEADER
 
 #define SPLIT_LINE_POS(fb)                                  \
 	(  (fb)->height                                     \
@@ -45,7 +45,7 @@ psplash_draw_msg (PSplashFB *fb, const char *msg)
 {
   int w, h;
 
-  psplash_fb_text_size (&w, &h, &radeon_font, msg);
+  psplash_fb_text_size (&w, &h, &FONT_DEF, msg);
 
   DBG("displaying '%s' %ix%i\n", msg, w, h);
 
@@ -62,7 +62,7 @@ psplash_draw_msg (PSplashFB *fb, const char *msg)
 			(fb->width-w)/2, 
 			SPLIT_LINE_POS(fb) - h,
 			PSPLASH_TEXT_COLOR,
-			&radeon_font,
+			&FONT_DEF,
 			msg);
 }
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/3 Double buffering support

From: Andrei Gherzan <[email protected]>

'psplash' uses only one buffer which can cause tearing artifacts. This change uses the FBIOPAN_DISPLAY ioctl as a way to handle page flipping and also does that after a vsync interrupt to remove any tearing issues.

---
 psplash-fb.c | 121 ++++++++++++++++++++++++++++++++++++++++++---------
 psplash-fb.h |   8 ++++
 psplash.c    |  10 ++++-
 3 files changed, 118 insertions(+), 21 deletions(-)
psplash-fb.c +101 -20
index c064d18..3cb5d2d 100644
@@ -18,6 +18,46 @@
 #include <endian.h>
 #include "psplash.h"
 
+static void
+psplash_wait_for_vsync(PSplashFB *fb)
+{
+  int err = ioctl(fb->fd, FBIO_WAITFORVSYNC, 0);
+  if (err != 0)
+    fprintf(stderr, "Error, FB vsync ioctl [%d]\n", err);
+}
+
+void
+psplash_fb_flip(PSplashFB *fb, int sync)
+{
+  char *tmp;
+
+  if (fb->double_buffering) {
+
+    /* Carry out the flip after a vsync */
+    psplash_wait_for_vsync(fb);
+
+    /* Switch the current activate area in fb */
+    if (fb->fb_var.yoffset == 0 ) {
+      fb->fb_var.yoffset = fb->real_height;
+    } else {
+      fb->fb_var.yoffset = 0;
+    }
+    if (ioctl(fb->fd, FBIOPAN_DISPLAY, &fb->fb_var) == -1 ) {
+      fprintf(stderr, "psplash_fb_flip: FBIOPAN_DISPLAY failed\n");
+    }
+
+    /* Switch the front and back data pointers */
+    tmp = fb->fdata;
+    fb->fdata = fb->bdata;
+    fb->bdata = tmp;
+
+    /* Sync new front to new back when requested */
+    if (sync) {
+      memcpy(fb->bdata, fb->fdata, fb->stride * fb->real_height);
+    }
+  }
+}
+
 void
 psplash_fb_destroy (PSplashFB *fb)
 {
@@ -163,6 +203,29 @@ psplash_fb_new (int angle, int fbdev_id)
       goto fail;
     }
 
+  /* Setup double virtual resolution for double buffering */
+  if (ioctl(fb->fd, FBIOPAN_DISPLAY, &fb_var) == -1) {
+    fprintf(stderr, "FBIOPAN_DISPLAY not supported, double buffering disabled");
+  } else {
+    if (fb_var.yres_virtual == fb_var.yres * 2) {
+      DBG("Virtual resolution already double");
+      fb->double_buffering = 1;
+    } else {
+      fb_var.yres_virtual = fb_var.yres * 2;
+      if (ioctl(fb->fd, FBIOPUT_VSCREENINFO, &fb_var) == -1) {
+        fprintf(stderr, "FBIOPUT_VSCREENINFO failed, double buffering disabled");
+      } else {
+        if (ioctl(fb->fd, FBIOGET_FSCREENINFO, &fb_fix) == -1) {
+          perror(" Error getting the fixed framebuffer info");
+          goto fail;
+        } else {
+          DBG("Virtual resolution set to double");
+          fb->double_buffering = 1;
+        }
+      }
+    }
+  }
+
   fb->real_width  = fb->width  = fb_var.xres;
   fb->real_height = fb->height = fb_var.yres;
   fb->bpp    = fb_var.bits_per_pixel;
@@ -201,8 +264,7 @@ psplash_fb_new (int angle, int fbdev_id)
       fb->width, fb->height, fb->bpp, fb->stride);
 
   fb->base = (char *) mmap ((caddr_t) NULL,
-			    /*fb_fix.smem_len */
-			    fb->stride * fb->height,
+			    fb_fix.smem_len,
 			    PROT_READ|PROT_WRITE,
 			    MAP_SHARED,
 			    fb->fd, 0);
@@ -217,6 +279,23 @@ psplash_fb_new (int angle, int fbdev_id)
 
   fb->data = fb->base + off;
 
+  if (fb->double_buffering) {
+    /* fb_var is needed when flipping the buffers */
+    memcpy(&fb->fb_var, &fb_var, sizeof(struct fb_var_screeninfo));
+    if (fb->fb_var.yoffset == 0) {
+      printf("to back\n");
+      fb->fdata = fb->data;
+      fb->bdata = fb->data + fb->stride * fb->height;
+    } else {
+      printf("to front\n");
+      fb->fdata = fb->data + fb->stride * fb->height;
+      fb->bdata = fb->data;
+    }
+  } else {
+    fb->fdata = fb->data;
+    fb->bdata = fb->data;
+  }
+
 #if 0
   /* FIXME: No support for 8pp as yet  */
   if (visual == FB_VISUAL_PSEUDOCOLOR
@@ -274,6 +353,8 @@ psplash_fb_plot_pixel (PSplashFB    *fb,
 		       uint8        green,
 		       uint8        blue)
 {
+  /* Always write to back data (bdata) which points to the right data with or
+   * without double buffering support */
   int off;
 
   if (x < 0 || x > fb->width-1 || y < 0 || y > fb->height-1)
@@ -301,22 +382,22 @@ psplash_fb_plot_pixel (PSplashFB    *fb,
       {
       case 24:
 #if __BYTE_ORDER == __BIG_ENDIAN
-        *(fb->data + off + 0) = red;
-        *(fb->data + off + 1) = green;
-        *(fb->data + off + 2) = blue;
+        *(fb->bdata + off + 0) = red;
+        *(fb->bdata + off + 1) = green;
+        *(fb->bdata + off + 2) = blue;
 #else
-        *(fb->data + off + 0) = blue;
-        *(fb->data + off + 1) = green;
-        *(fb->data + off + 2) = red;
+        *(fb->bdata + off + 0) = blue;
+        *(fb->bdata + off + 1) = green;
+        *(fb->bdata + off + 2) = red;
 #endif
         break;
       case 32:
-        *(volatile uint32_t *) (fb->data + off)
+        *(volatile uint32_t *) (fb->bdata + off)
           = (red << 16) | (green << 8) | (blue);
         break;
 
       case 16:
-        *(volatile uint16_t *) (fb->data + off)
+        *(volatile uint16_t *) (fb->bdata + off)
 	  = ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
         break;
       default:
@@ -328,21 +409,21 @@ psplash_fb_plot_pixel (PSplashFB    *fb,
       {
       case 24:
 #if __BYTE_ORDER == __BIG_ENDIAN
-        *(fb->data + off + 0) = blue;
-        *(fb->data + off + 1) = green;
-        *(fb->data + off + 2) = red;
+        *(fb->bdata + off + 0) = blue;
+        *(fb->bdata + off + 1) = green;
+        *(fb->bdata + off + 2) = red;
 #else
-        *(fb->data + off + 0) = red;
-        *(fb->data + off + 1) = green;
-        *(fb->data + off + 2) = blue;
+        *(fb->bdata + off + 0) = red;
+        *(fb->bdata + off + 1) = green;
+        *(fb->bdata + off + 2) = blue;
 #endif
         break;
       case 32:
-        *(volatile uint32_t *) (fb->data + off)
+        *(volatile uint32_t *) (fb->bdata + off)
           = (blue << 16) | (green << 8) | (red);
         break;
       case 16:
-        *(volatile uint16_t *) (fb->data + off)
+        *(volatile uint16_t *) (fb->bdata + off)
 	  = ((blue >> 3) << 11) | ((green >> 2) << 5) | (red >> 3);
         break;
       default:
@@ -353,13 +434,13 @@ psplash_fb_plot_pixel (PSplashFB    *fb,
     switch (fb->bpp)
       {
       case 32:
-        *(volatile uint32_t *) (fb->data + off)
+        *(volatile uint32_t *) (fb->bdata + off)
 	  = ((red >> (8 - fb->red_length)) << fb->red_offset) 
 	      | ((green >> (8 - fb->green_length)) << fb->green_offset)
 	      | ((blue >> (8 - fb->blue_length)) << fb->blue_offset);
         break;
       case 16:
-        *(volatile uint16_t *) (fb->data + off)
+        *(volatile uint16_t *) (fb->bdata + off)
 	  = ((red >> (8 - fb->red_length)) << fb->red_offset) 
 	      | ((green >> (8 - fb->green_length)) << fb->green_offset)
 	      | ((blue >> (8 - fb->blue_length)) << fb->blue_offset);
psplash-fb.h +8 -0
index d0dce10..2f0cdff 100644
@@ -29,6 +29,7 @@ enum RGBMode {
 typedef struct PSplashFB
 {
   int            fd;			
+  struct fb_var_screeninfo fb_var;
   struct termios save_termios;	        
   int            type;		        
   int            visual;		
@@ -38,6 +39,11 @@ typedef struct PSplashFB
   char		*data;
   char		*base;
 
+  /* Support for double buffering */
+  int		double_buffering;
+  char		*bdata;
+  char		*fdata;
+
   int            angle, fbdev_id;
   int            real_width, real_height;
 
@@ -93,5 +99,7 @@ psplash_fb_draw_text (PSplashFB         *fb,
 		      const PSplashFont *font,
 		      const char        *text);
 
+void
+psplash_fb_flip(PSplashFB *fb, int sync);
 
 #endif
psplash.c +9 -1
index f6442f1..61122fc 100644
@@ -126,6 +126,7 @@ parse_command (PSplashFB *fb, char *string)
       return 1;
     }
 
+  psplash_fb_flip(fb, 0);
   return 0;
 }
 
@@ -309,8 +310,15 @@ main (int argc, char** argv)
   psplash_draw_msg (fb, PSPLASH_STARTUP_MSG);
 #endif
 
-  psplash_main (fb, pipe_fd, 0);
+  /* Scene set so let's flip the buffers. */
+  /* The first time we also synchronize the buffers so we can build on an
+   * existing scene. After the first scene is set in both buffers, only the
+   * text and progress bar change which overwrite the specific areas with every
+   * update.
+   */
+  psplash_fb_flip(fb, 1);
 
+  psplash_main (fb, pipe_fd, 0);
 
   psplash_fb_destroy (fb);
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH 3/3 Add configure flags for fullscreen logo and no startup message

In reply to Andrei Gherzan

From: Andrei Gherzan <[email protected]>

---
 Makefile.am      |  2 +-
 configure.ac     | 18 ++++++++++++++++++
 psplash-config.h |  4 ++++
 3 files changed, 23 insertions(+), 1 deletion(-)
Makefile.am +1 -1
index 3721a6e..3f1cfc2 100644
@@ -1,6 +1,6 @@
 bin_PROGRAMS=psplash psplash-write
 
-AM_CFLAGS = $(GCC_FLAGS) -D_GNU_SOURCE -DFONT_HEADER=\"$(FONT_NAME)-font.h\" -DFONT_DEF=$(FONT_NAME)_font
+AM_CFLAGS = $(GCC_FLAGS) $(EXTRA_GCC_FLAGS) -D_GNU_SOURCE -DFONT_HEADER=\"$(FONT_NAME)-font.h\" -DFONT_DEF=$(FONT_NAME)_font
 
 psplash_SOURCES = psplash.c psplash.h psplash-fb.c psplash-fb.h \
                   psplash-console.c psplash-console.h           \
configure.ac +18 -0
index 9e78ac0..e2b7f58 100644
@@ -20,6 +20,24 @@ AC_ARG_WITH([font],
     [FONT_NAME=radeon])
 AC_SUBST([FONT_NAME])
 
+AC_ARG_ENABLE([startup-msg],
+    AS_HELP_STRING([--disable-startup-msg], [Disable text banner output on startup]),
+    [disable_startup_msg=true],
+    [disable_startup_msg=false])
+AS_IF([test x$disable_startup_msg = xtrue], [
+    EXTRA_GCC_FLAGS="$EXTRA_GCC_FLAGS -DPSPLASH_DISABLE_STARTUP_MSG"
+])
+
+AC_ARG_ENABLE([img-fullscreen],
+    AS_HELP_STRING([--enable-img-fullscreen], [Enable the logo image in fullscreen mode)]),
+    [img_fullscreen=true],
+    [img_fullscreen=false])
+AS_IF([test x$img_fullscreen = xtrue], [
+    EXTRA_GCC_FLAGS="$EXTRA_GCC_FLAGS -DPSPLASH_IMG_FULLSCREEN=1"
+])
+
+AC_SUBST(EXTRA_GCC_FLAGS)
+
 AC_OUTPUT([
 Makefile
 ])
psplash-config.h +4 -0
index 82bb76d..ecbf3df 100644
@@ -20,10 +20,14 @@
 #define _HAVE_PSPLASH_CONFIG_H
 
 /* Text to output on program start; if undefined, output nothing */
+#ifndef PSPLASH_DISABLE_STARTUP_MSG
 #define PSPLASH_STARTUP_MSG ""
+#endif
 
 /* Bool indicating if the image is fullscreen, as opposed to split screen */
+#ifndef PSPLASH_IMG_FULLSCREEN
 #define PSPLASH_IMG_FULLSCREEN 0
+#endif
 
 /* Position of the image split from top edge, numerator of fraction */
 #define PSPLASH_IMG_SPLIT_NUMERATOR 5
Signature · 1 line
2.17.1