socsvn commit: r270722 - soc2014/seiya/bootsplash/sys/dev/fb

seiya at FreeBSD.org seiya at FreeBSD.org
Fri Jul 11 07:16:58 UTC 2014


Author: seiya
Date: Fri Jul 11 07:16:57 2014
New Revision: 270722
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=270722

Log:
  draw animation a part of the screen

Modified:
  soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c

Modified: soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c
==============================================================================
--- soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c	Fri Jul 11 06:52:48 2014	(r270721)
+++ soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c	Fri Jul 11 07:16:57 2014	(r270722)
@@ -42,12 +42,24 @@
 #include <dev/fb/vgareg.h>
 #include <isa/isareg.h>
 
+/* only support 1024x768 */
+#define SCREEN_WIDTH  1024
+#define SCREEN_HEIGHT 768
+
 static void update_animation(void *unused);
 static int load_bmp(video_adapter_t *adp, BMP_INFO *bmp_info, void* data);
-static int draw_bmp(video_adapter_t *adp, BMP_INFO *bmp_info, int y, int height, int width);
+static int draw_bmp(int iy, int sy, int sx, int width, int height);
 
 static video_adapter_t *adp = NULL;
-BMP_INFO	bmp_info;
+static BMP_INFO	bmp_info;
+static int	background_y_origin	= -1;
+static int	background_enabled	= 1;
+static int	animation_y_origin	= -1;
+static int	animation_y		= -1;
+static int	animation_x		= -1;
+static int	animation_width		= -1;
+static int	animation_height	= -1;
+static int	animation_enabled	= 1;
 
 int
 bsplash_early_init(video_adapter_t *_adp)
@@ -61,11 +73,94 @@
 {
 	caddr_t		image = NULL;
 	void		*p;
+	char		*s;
 
 	if(adp == NULL)
 		return 1;
 
-	// get a pointer to the first image
+	/*
+	 *  get parameters from /boot/loader.conf
+	 */
+        // load "bsplash_background_y_origin"
+	if ((s = getenv("bsplash_background_y_origin")) == NULL) {
+		if (bootverbose)
+			printf("bsplash: cannot load \"bsplash_background_y_origin\"\n");
+		background_enabled = 0;
+	} else {
+		background_y_origin = strtol(s, NULL, 10);
+	}
+	freeenv(s);
+
+        // load "bsplash_animation_y_origin"
+	if ((s = getenv("bsplash_animation_y_origin")) == NULL) {
+		if (bootverbose)
+			printf("bsplash: cannot load \"bsplash_animation_y_origin\"\n");
+		animation_enabled = 0;
+	} else {
+		animation_y_origin = strtol(s, NULL, 10);
+	}
+	freeenv(s);
+
+        // load "bsplash_animation_y"
+	if ((s = getenv("bsplash_animation_y")) == NULL) {
+		if (bootverbose)
+			printf("bsplash: cannot load \"bsplash_animation_y\"\n");
+		animation_enabled = 0;
+	} else {
+		animation_y = strtol(s, NULL, 10);
+	}
+	freeenv(s);
+
+        // load "bsplash_animation_x"
+	if ((s = getenv("bsplash_animation_x")) == NULL) {
+		if (bootverbose)
+			printf("bsplash: cannot load \"bsplash_animation_x\"\n");
+		animation_enabled = 0;
+	} else {
+		animation_x = strtol(s, NULL, 10);
+	}
+	freeenv(s);
+
+        // load "bsplash_animation_width"
+	if ((s = getenv("bsplash_animation_width")) == NULL) {
+		if (bootverbose)
+			printf("bsplash: cannot load \"bsplash_animation_width\"\n");
+		animation_enabled = 0;
+	} else {
+		animation_width = strtol(s, NULL, 10);
+	}
+	freeenv(s);
+
+        // load "bsplash_animation_height"
+	if ((s = getenv("bsplash_animation_height")) == NULL) {
+		if (bootverbose)
+			printf("bsplash: cannot load \"bsplash_animation_height\"\n");
+		animation_enabled = 0;
+	} else {
+		animation_height = strtol(s, NULL, 10);
+	}
+	freeenv(s);
+
+	/*
+	 *  for debugging
+	 */
+	if (bootverbose) {
+		printf("bsplash: background is %s, img_y=%d\n",
+		    (background_enabled)? "enabled" : "disabled",
+                    background_y_origin);
+		printf("bsplash: animation is %s (y,x)=(%d,%d), img_y=%d, height=%d, width=%d\n",
+		    (animation_enabled)? "enabled" : "disabled",
+		    animation_y,
+		    animation_x,
+		    animation_y_origin,
+		    animation_height,
+		    animation_width);
+	}
+
+	/*
+	 *  load the image
+	 */
+	// get a pointer to the bsplash_image
 	image = preload_search_by_type("bsplash_image");
 
 	if (image == NULL){
@@ -80,11 +175,17 @@
                 return 1;
         }
 
+	/*
+	 *  change video mode
+	 */
 	if (vidd_set_mode(adp, M_VESA_CG1024x768) != 0)
 		return 1;
 
-	if (draw_bmp(adp, &bmp_info, 0, 1024, 768) != 0){
-		printf("bsplash: failed to draw BMP\n");
+	/*
+	 *  draw background
+	 */
+	if (background_enabled && draw_bmp(background_y_origin, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) != 0){
+		printf("bsplash: failed to draw BMP (background)\n");
                 return 1;
         }
 
@@ -101,25 +202,28 @@
 update_animation(void *unused)
 {
 	static int	count = 0;
-	static int	y = 0;
+	static int	iy;
 	char		*s;
 	int		progress = 0;
 
+	iy = animation_y_origin;
 	for (;;){
-		if (draw_bmp(adp, &bmp_info, y, 1024, 768) == 0){
-			y += 768;
+		// update animation
+		if (draw_bmp(iy, animation_y, animation_x, animation_width, animation_height) == 0){
+			iy += animation_height;
 		}else{
-			y = 0;
-			if(draw_bmp(adp, &bmp_info, y, 1024, 768) == 0) /* try again */
-				y += 768;
+			iy = animation_y_origin;
+			if (draw_bmp(iy, animation_y, animation_x, animation_width, animation_height) == 0)
+				iy += animation_height;
 		}
 
-		s = getenv("BOOT_PROGRESS");
-		if (s != NULL){
+		// get the progress of boot
+		if ((s = getenv("BOOT_PROGRESS")) != NULL){
 			progress = strtol(s, NULL, 10);
 			freeenv(s);
 		}
 
+		// boot takes too long
 		if (progress >= 100 || count > 50 /* FXIME */){
 			/* terminate boot splash */
 			vidd_set_mode(adp, M_TEXT_80x25);
@@ -141,7 +245,7 @@
 		return 1;
 
 	if (bmp_init(bmp_info, (u_char *)data, info.vi_width,
-		     info.vi_height, info.vi_depth) !=0)
+		     info.vi_height, info.vi_depth) != 0)
 		return 1;
 
 	return 0;
@@ -149,10 +253,10 @@
 
 
 static int
-draw_bmp(video_adapter_t *adp, BMP_INFO *bmp_info, int y, int width, int height)
+draw_bmp(int iy, int sy, int sx, int width, int height)
 {
 
-	if (bmp_draw(adp, bmp_info, 0, 0, y, width, height))
+	if (bmp_draw(adp, &bmp_info, sx, sy, iy, width, height) != 0)
 		return 1;
 
 	return 0;


More information about the svn-soc-all mailing list