@@ -144,6 +144,9 @@ void fb_unblit(u32 x, u32 y, u32 w, u32 h, void *data, u32 stride)
144144{
145145 u8 * p = data ;
146146
147+ if (!console .initialized )
148+ return ;
149+
147150 for (u32 i = 0 ; i < h ; i ++ ) {
148151 for (u32 j = 0 ; j < w ; j ++ ) {
149152 rgb_t color = fb_get_pixel (x + j , y + i );
@@ -157,6 +160,9 @@ void fb_unblit(u32 x, u32 y, u32 w, u32 h, void *data, u32 stride)
157160
158161void fb_fill (u32 x , u32 y , u32 w , u32 h , rgb_t color )
159162{
163+ if (!console .initialized )
164+ return ;
165+
160166 u32 c = rgb2pixel_30 (color );
161167 for (u32 i = 0 ; i < h ; i ++ )
162168 memset32 (& fb .ptr [x + (y + i ) * fb .stride ], c , w * 4 );
@@ -165,34 +171,52 @@ void fb_fill(u32 x, u32 y, u32 w, u32 h, rgb_t color)
165171
166172void fb_clear (rgb_t color )
167173{
174+ if (!console .initialized )
175+ return ;
176+
168177 u32 c = rgb2pixel_30 (color );
169178 memset32 (fb .ptr , c , fb .stride * fb .height * 4 );
170179 fb_update ();
171180}
172181
173182void fb_blit_image (u32 x , u32 y , const struct image * img )
174183{
184+ if (!console .initialized )
185+ return ;
186+
175187 fb_blit (x , y , img -> width , img -> height , img -> ptr , img -> width , PIX_FMT_XRGB );
176188}
177189
178190void fb_unblit_image (u32 x , u32 y , struct image * img )
179191{
192+ if (!console .initialized )
193+ return ;
194+
180195 fb_unblit (x , y , img -> width , img -> height , img -> ptr , img -> width );
181196}
182197
183198void fb_blit_logo (const struct image * logo )
184199{
200+ if (!console .initialized )
201+ return ;
202+
185203 fb_blit_image ((fb .width - logo -> width ) / 2 , (fb .height - logo -> height ) / 2 , logo );
186204}
187205
188206void fb_display_logo (void )
189207{
208+ if (!console .initialized )
209+ return ;
210+
190211 printf ("fb: display logo\n" );
191212 fb_blit_logo (logo );
192213}
193214
194215void fb_restore_logo (void )
195216{
217+ if (!console .initialized )
218+ return ;
219+
196220 if (!orig_logo .ptr )
197221 return ;
198222 fb_blit_logo (& orig_logo );
@@ -259,6 +283,9 @@ static void fb_putchar(u8 c)
259283
260284void fb_console_scroll (u32 n )
261285{
286+ if (!console .initialized )
287+ return ;
288+
262289 u32 row = 0 ;
263290 n = min (n , console .cursor .row );
264291 for (; row < console .cursor .max_row - n ; ++ row )
@@ -270,6 +297,9 @@ void fb_console_scroll(u32 n)
270297
271298void fb_console_reserve_lines (u32 n )
272299{
300+ if (!console .initialized )
301+ return ;
302+
273303 if ((console .cursor .max_row - console .cursor .row ) <= n )
274304 fb_console_scroll (1 + n - (console .cursor .max_row - console .cursor .row ));
275305 fb_update ();
@@ -404,14 +434,14 @@ void fb_shutdown(bool restore_logo)
404434 return ;
405435
406436 console .active = false;
407- console .initialized = false;
408437 fb_clear_console ();
409438 if (restore_logo ) {
410439 fb_restore_logo ();
411440 free (orig_logo .ptr );
412441 orig_logo .ptr = NULL ;
413442 }
414443 free (fb .ptr );
444+ console .initialized = false;
415445}
416446
417447void fb_reinit (void )
0 commit comments