@@ -101,6 +101,21 @@ const EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION mProgressBarDefaultColor = {
101101//
102102BOOLEAN mGraphicsGood = FALSE;
103103
104+ //
105+ // Set to TRUE after the first GOP lookup attempt to avoid retrying.
106+ //
107+ BOOLEAN mGopChecked = FALSE;
108+
109+ //
110+ // Set to TRUE when GOP is unavailable and text console is used instead.
111+ //
112+ BOOLEAN mTextFallback = FALSE;
113+
114+ //
115+ // Text foreground color for the text fallback progress bar.
116+ //
117+ UINTN mTextFallbackColor ;
118+
104119/**
105120 Internal function used to find the bounds of the white logo (on black or
106121 red background).
@@ -360,7 +375,9 @@ DisplayUpdateProgress (
360375 //
361376 // Find Graphics Output Protocol if not already set. 1 time.
362377 //
363- if (mGop == NULL ) {
378+ if (!mGopChecked ) {
379+ mGopChecked = TRUE;
380+
364381 Status = gBS -> HandleProtocol (
365382 gST -> ConsoleOutHandle ,
366383 & gEfiGraphicsOutputProtocolGuid ,
@@ -370,23 +387,118 @@ DisplayUpdateProgress (
370387 Status = gBS -> LocateProtocol (& gEfiGraphicsOutputProtocolGuid , NULL , (VOID * * )& mGop );
371388 if (EFI_ERROR (Status )) {
372389 mGop = NULL ;
373- DEBUG ((DEBUG_ERROR , "Show Progress Function could not locate GOP. Status = %r\n" , Status ));
374- return EFI_NOT_READY ;
390+ DEBUG ((DEBUG_WARN , "Show Progress Function could not locate GOP. Status = %r. Using text fallback. \n" , Status ));
391+ mTextFallback = TRUE ;
375392 }
376393 }
377394
378- //
379- // Run once
380- //
381- FindDim ();
395+ if (!mTextFallback ) {
396+ //
397+ // Run once
398+ //
399+ FindDim ();
400+
401+ if (!mGraphicsGood ) {
402+ DEBUG ((DEBUG_WARN , "Graphics Not Good. Using text fallback for progress display.\n" ));
403+ mTextFallback = TRUE;
404+ }
405+ }
382406 }
383407
384408 //
385- // Make sure a valid start, end, and size info are available (find the Logo)
409+ // Text fallback rendering when GOP is unavailable
386410 //
387- if (!mGraphicsGood ) {
388- DEBUG ((DEBUG_INFO , "Graphics Not Good. Not doing any onscreen visual display\n" ));
389- return EFI_NOT_READY ;
411+ if (mTextFallback ) {
412+ UINTN CurrentAttribute ;
413+
414+ //
415+ // Do special init on first call of each progress session
416+ //
417+ if (mPreviousProgress == 100 ) {
418+ Print (L"\n" );
419+
420+ //
421+ // Convert pixel color to text foreground color
422+ //
423+ if (Color == NULL ) {
424+ mTextFallbackColor = EFI_WHITE ;
425+ } else {
426+ mTextFallbackColor = EFI_BLACK ;
427+ if (Color -> Pixel .Blue >= 0x40 ) {
428+ mTextFallbackColor |= EFI_BLUE ;
429+ }
430+
431+ if (Color -> Pixel .Green >= 0x40 ) {
432+ mTextFallbackColor |= EFI_GREEN ;
433+ }
434+
435+ if (Color -> Pixel .Red >= 0x40 ) {
436+ mTextFallbackColor |= EFI_RED ;
437+ }
438+
439+ if ((Color -> Pixel .Blue >= 0xC0 ) || (Color -> Pixel .Green >= 0xC0 ) || (Color -> Pixel .Red >= 0xC0 )) {
440+ mTextFallbackColor |= EFI_BRIGHT ;
441+ }
442+
443+ if (mTextFallbackColor == EFI_BLACK ) {
444+ mTextFallbackColor = EFI_WHITE ;
445+ }
446+ }
447+
448+ //
449+ // Clear previous
450+ //
451+ mPreviousProgress = 0 ;
452+ }
453+
454+ //
455+ // Can not update progress bar if Completion is less than previous
456+ //
457+ if (Completion < mPreviousProgress ) {
458+ DEBUG ((DEBUG_WARN , "WARNING: Completion (%d) should not be lesss than Previous (%d)!!!\n" , Completion , mPreviousProgress ));
459+ return EFI_INVALID_PARAMETER ;
460+ }
461+
462+ //
463+ // Save current text color
464+ //
465+ CurrentAttribute = (UINTN )gST -> ConOut -> Mode -> Attribute ;
466+
467+ //
468+ // Print progress percentage
469+ //
470+ Print (L"\rUpdate Progress - %3d%% " , Completion );
471+
472+ //
473+ // Set progress bar color
474+ //
475+ gST -> ConOut -> SetAttribute (
476+ gST -> ConOut ,
477+ EFI_TEXT_ATTR (mTextFallbackColor , EFI_BLACK )
478+ );
479+
480+ //
481+ // Print completed portion of progress bar
482+ //
483+ for (Index = 0 ; Index < Completion / 2 ; Index ++ ) {
484+ Print (L"%c" , BLOCKELEMENT_FULL_BLOCK );
485+ }
486+
487+ //
488+ // Restore text color
489+ //
490+ gST -> ConOut -> SetAttribute (gST -> ConOut , CurrentAttribute );
491+
492+ //
493+ // Print remaining portion of progress bar
494+ //
495+ for ( ; Index < 50 ; Index ++ ) {
496+ Print (L"%c" , BLOCKELEMENT_LIGHT_SHADE );
497+ }
498+
499+ mPreviousProgress = Completion ;
500+
501+ return EFI_SUCCESS ;
390502 }
391503
392504 //
0 commit comments