Index: uspace/srv/fb/fb.c
===================================================================
--- uspace/srv/fb/fb.c	(revision 67ebf2120856a1d0365559c5183453ee6f898495)
+++ uspace/srv/fb/fb.c	(revision 4527fb5b9cd99ab3d0607e26e017b7ea0f92d227)
@@ -94,4 +94,7 @@
 	unsigned int pixelbytes;
 	unsigned int glyphbytes;
+
+	/** Pre-rendered mask for rendering glyphs. Specific for the visual. */
+	uint8_t *glyphs;
 	
 	rgb_conv_t rgb_conv;
@@ -123,12 +126,11 @@
 	attr_rgb_t attr;
 
-	/** Pre-rendered mask for rendering glyphs. Different viewports
+	uint8_t *bgpixel;
+
+	/**
+	 * Glyph drawing function for this viewport.  Different viewports
 	 * might use different drawing functions depending on whether their
-	 * scanlines are aligned on a word boundary.*/
-	uint8_t *glyphs;
-
-	uint8_t *bgpixel;
-
-	/** Glyph drawing function for this viewport. */
+	 * scanlines are aligned on a word boundary.
+	 */
 	dg_t dglyph;
 	
@@ -422,5 +424,5 @@
 			}
 
-			(*vport->dglyph)(x, y, false, vport->glyphs, glyph,
+			(*vport->dglyph)(x, y, false, screen.glyphs, glyph,
 			    fg_color, bg_color);
 			x += FONT_WIDTH;
@@ -450,24 +452,21 @@
  * Convert glyphs from device independent font
  * description to current visual representation.
- *
- * @param vport Viewport
- *
- */
-static void render_glyphs(viewport_t* vport)
+ */
+static void render_glyphs(void)
 {
 	unsigned int glyph;
-	
+
 	for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
 		unsigned int y;
-		
+
 		for (y = 0; y < FONT_SCANLINES; y++) {
 			unsigned int x;
-			
+
 			for (x = 0; x < FONT_WIDTH; x++) {
-				screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes],
+				screen.rgb_conv(&screen.glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes],
 				    (fb_font[glyph][y] & (1 << (7 - x)))
 				    ? 0xffffff : 0x000000);
-				
-				screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes],
+
+				screen.rgb_conv(&screen.glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes],
 				    (fb_font[glyph][y] & (1 << (7 - x)))
 				    ? 0x000000 : 0xffffff);
@@ -475,6 +474,4 @@
 		}
 	}
-	
-	screen.rgb_conv(vport->bgpixel, vport->attr.bg_color);
 }
 
@@ -505,5 +502,4 @@
 	unsigned int rows = height / FONT_SCANLINES;
 	unsigned int bbsize = cols * rows * sizeof(bb_cell_t);
-	unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes;
 	unsigned int word_size = sizeof(unsigned long);
 	
@@ -512,19 +508,11 @@
 		return ENOMEM;
 	
-	uint8_t *glyphs = (uint8_t *) malloc(glyphsize);
-	if (!glyphs) {
+	uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes);
+	if (!bgpixel) {
 		free(backbuf);
 		return ENOMEM;
 	}
-	
-	uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes);
-	if (!bgpixel) {
-		free(glyphs);
-		free(backbuf);
-		return ENOMEM;
-	}
 
 	backbuf_clear(backbuf, cols * rows, DEFAULT_FGCOLOR, DEFAULT_BGCOLOR);
-	memset(glyphs, 0, glyphsize);
 	memset(bgpixel, 0, screen.pixelbytes);
 	
@@ -540,5 +528,4 @@
 	viewports[i].attr.fg_color = DEFAULT_FGCOLOR;
 	
-	viewports[i].glyphs = glyphs;
 	viewports[i].bgpixel = bgpixel;
 
@@ -570,5 +557,5 @@
 	viewports[i].initialized = true;
 	
-	render_glyphs(&viewports[i]);
+	screen.rgb_conv(viewports[i].bgpixel, viewports[i].attr.bg_color);
 	
 	return i;
@@ -588,4 +575,6 @@
     unsigned int scan, unsigned int visual)
 {
+	unsigned int glyphsize;
+	uint8_t *glyphs;
 	switch (visual) {
 	case VISUAL_INDIRECT_8:
@@ -632,4 +621,14 @@
 	screen.glyphscanline = FONT_WIDTH * screen.pixelbytes;
 	screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES;
+
+	glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes;
+	glyphs = (uint8_t *) malloc(glyphsize);
+	if (!glyphs)
+		return false;
+	
+	memset(glyphs, 0, glyphsize);
+	screen.glyphs = glyphs;
+
+	render_glyphs();
 	
 	/* Create first viewport */
@@ -789,5 +788,5 @@
 	bg_color = vport->backbuf[BB_POS(vport, col, row)].bg_color;
 
-	(*vport->dglyph)(x, y, cursor, vport->glyphs, glyph,
+	(*vport->dglyph)(x, y, cursor, screen.glyphs, glyph,
 	    fg_color, bg_color);
 }
@@ -1635,6 +1634,4 @@
 			}
 			viewports[i].initialized = false;
-			if (viewports[i].glyphs)
-				free(viewports[i].glyphs);
 			if (viewports[i].bgpixel)
 				free(viewports[i].bgpixel);
