alder_lake_bios/Oem/L05/FeatureCommon/InsydeL05ModulePkg/Library/ProgressBarLib/ProgressBarLib.c

607 lines
26 KiB
C

/** @file
Instance of Progress Bar Services Library.
;******************************************************************************
;* Copyright (c) 2021, Insyde Software Corporation. All Rights Reserved.
;*
;* You may not reproduce, distribute, publish, display, perform, modify, adapt,
;* transmit, broadcast, present, recite, release, license or otherwise exploit
;* any part of this publication in any form, by any means, without the prior
;* written permission of Insyde Software Corporation.
;*
;******************************************************************************
*/
#include <Uefi.h>
#include <PiDxe.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiLib.h>
#include <Library/PcdLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DxeServicesLib.h>
#include <Library/PrintStrToImageLib.h>
#include <Library/ProgressBarLib.h>
#include <Protocol/GraphicsOutput.h>
#include <Protocol/TgaDecoder.h>
//
// Progress image type definitions
//
#define PROGRESS_BOARD 1
#define PROGRESS_BAR 2
#define PROGRESS_FULL_BAR 3
STATIC EFI_GRAPHICS_OUTPUT_PROTOCOL *mGop = NULL;
STATIC EFI_TGA_DECODER_PROTOCOL *mTgaDecoder = NULL;
STATIC UINTN mCompletion = PROCESS_PERCENTAGE_VALUE + 1;
STATIC UINTN mBltPixelHeight = 0;
STATIC UINT8 mProgressBoardTga[] = {
0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x02, 0x10, 0x00,
0x18, 0x00, 0x83, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x02, 0x7B, 0x7B, 0x7B, 0xB4, 0xB4, 0xB4,
0xE6, 0xE6, 0xE6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x9F, 0xFF, 0xFF, 0xFF, 0x03, 0xE6, 0xE6, 0xE6, 0xB4, 0xB4, 0xB4, 0x7B, 0x7B,
0x7B, 0x02, 0x02, 0x02, 0x83, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, 0x04, 0x55, 0x55, 0x55,
0xFC, 0xFC, 0xFC, 0x71, 0x71, 0x71, 0x4B, 0x4B, 0x4B, 0x18, 0x18, 0x18, 0xFF, 0x00, 0x00, 0x00,
0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x9F, 0x00, 0x00, 0x00,
0x04, 0x18, 0x18, 0x18, 0x4B, 0x4B, 0x4B, 0x71, 0x71, 0x71, 0xFC, 0xFC, 0xFC, 0x55, 0x55, 0x55,
0x82, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, 0x01, 0x57, 0x57, 0x57, 0xB1, 0xB1, 0xB1, 0xFF,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xA7,
0x00, 0x00, 0x00, 0x01, 0xB1, 0xB1, 0xB1, 0x57, 0x57, 0x57, 0x81, 0x00, 0x00, 0x00, 0x02, 0x00,
0x00, 0x00, 0x55, 0x55, 0x55, 0xB1, 0xB1, 0xB1, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,
0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xA9, 0x00, 0x00, 0x00, 0x02, 0xB1, 0xB1, 0xB1,
0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x02, 0xFD, 0xFD, 0xFD, 0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xAB, 0x00, 0x00,
0x00, 0x01, 0xFD, 0xFD, 0xFD, 0x02, 0x02, 0x02, 0x01, 0x7C, 0x7C, 0x7C, 0x71, 0x71, 0x71, 0xFF,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xAB,
0x00, 0x00, 0x00, 0x01, 0x71, 0x71, 0x71, 0x7C, 0x7C, 0x7C, 0x01, 0xB4, 0xB4, 0xB4, 0x4A, 0x4A,
0x4A, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00,
0x00, 0xAB, 0x00, 0x00, 0x00, 0x01, 0x4A, 0x4A, 0x4A, 0xB4, 0xB4, 0xB4, 0x01, 0xE6, 0xE6, 0xE6,
0x18, 0x18, 0x18, 0x81, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0xFF, 0x00, 0x00, 0x00, 0xFF,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x01, 0x81, 0x00, 0x00, 0x00, 0x01, 0x18, 0x18, 0x18, 0xE6, 0xE6, 0xE6, 0x01, 0xE7,
0xE7, 0xE7, 0x17, 0x17, 0x17, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00, 0x00, 0x00, 0xAB, 0x00, 0x00, 0x00, 0x01, 0x17, 0x17, 0x17, 0xE7, 0xE7, 0xE7,
0x01, 0xB5, 0xB5, 0xB5, 0x49, 0x49, 0x49, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xAB, 0x00, 0x00, 0x00, 0x01, 0x49, 0x49, 0x49, 0xB5,
0xB5, 0xB5, 0x01, 0x7D, 0x7D, 0x7D, 0x71, 0x71, 0x71, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xAB, 0x00, 0x00, 0x00, 0x01, 0x71, 0x71,
0x71, 0x7D, 0x7D, 0x7D, 0x01, 0x04, 0x04, 0x04, 0xF9, 0xF9, 0xF9, 0xFF, 0x00, 0x00, 0x00, 0xFF,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xAB, 0x00, 0x00, 0x00, 0x01,
0xF9, 0xF9, 0xF9, 0x04, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00, 0x57, 0x57, 0x57, 0xAF, 0xAF, 0xAF,
0x82, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,
0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
0x82, 0x00, 0x00, 0x00, 0x02, 0xAF, 0xAF, 0xAF, 0x57, 0x57, 0x57, 0x00, 0x00, 0x00, 0x81, 0x00,
0x00, 0x00, 0x02, 0x5C, 0x5C, 0x5C, 0xAE, 0xAE, 0xAE, 0x01, 0x01, 0x01, 0xFF, 0x00, 0x00, 0x00,
0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x00, 0x00,
0x02, 0x01, 0x01, 0x01, 0xAE, 0xAE, 0xAE, 0x5C, 0x5C, 0x5C, 0x81, 0x00, 0x00, 0x00, 0x82, 0x00,
0x00, 0x00, 0x04, 0x59, 0x59, 0x59, 0xF9, 0xF9, 0xF9, 0x6D, 0x6D, 0x6D, 0x48, 0x48, 0x48, 0x17,
0x17, 0x17, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00,
0x00, 0x00, 0x9F, 0x00, 0x00, 0x00, 0x04, 0x17, 0x17, 0x17, 0x48, 0x48, 0x48, 0x6D, 0x6D, 0x6D,
0xF9, 0xF9, 0xF9, 0x59, 0x59, 0x59, 0x82, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x03, 0x05,
0x05, 0x05, 0x7F, 0x7F, 0x7F, 0xB6, 0xB6, 0xB6, 0xE7, 0xE7, 0xE7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x9F, 0xFF, 0xFF, 0xFF, 0x03,
0xE7, 0xE7, 0xE7, 0xB6, 0xB6, 0xB6, 0x7F, 0x7F, 0x7F, 0x05, 0x05, 0x05, 0x83, 0x00, 0x00, 0x00
};
STATIC UINT8 mProgressBarTga[] = {
0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x10, 0x00,
0x18, 0x00, 0x83, 0x00, 0x00, 0x00, 0x03, 0x09, 0x09, 0x09, 0xBB, 0xBB, 0xBB, 0xF0, 0xF0, 0xF0,
0xFD, 0xFD, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0x99, 0xFF, 0xFF, 0xFF, 0x82, 0x00, 0x00, 0x00, 0x00,
0x90, 0x90, 0x90, 0x81, 0xFE, 0xFE, 0xFE, 0x01, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF,
0xFF, 0xFF, 0x94, 0xFF, 0xFF, 0xFF, 0x01, 0xFE, 0xFE, 0xFE, 0x55, 0x55, 0x55, 0x82, 0x00, 0x00,
0x00, 0x81, 0x00, 0x00, 0x00, 0x01, 0xAA, 0xAA, 0xAA, 0xF9, 0xF9, 0xF9, 0x81, 0x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0xF9, 0xF9, 0xF9, 0xAD, 0xAD, 0xAD, 0x81, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, 0x01, 0x95,
0x95, 0x95, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x97, 0xFF, 0xFF, 0xFF, 0x01, 0xFE, 0xFE,
0xFE, 0x95, 0x95, 0x95, 0x82, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x03, 0x11, 0x11, 0x11,
0xBF, 0xBF, 0xBF, 0xEF, 0xEF, 0xEF, 0xFD, 0xFD, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0x91, 0xFF, 0xFF,
0xFF, 0x03, 0xFD, 0xFD, 0xFD, 0xEF, 0xEF, 0xEF, 0xBF, 0xBF, 0xBF, 0x11, 0x11, 0x11, 0x83, 0x00,
0x00, 0x00
};
/**
Paint progress percentage.
@param Completion Percentage of progressing.
@retval EFI_SUCCESS The operation completed successfully.
@retval Others An unexpected error occurred.
**/
EFI_STATUS
ProgressBarPercentage (
IN UINTN Completion
)
{
EFI_STATUS Status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
UINT32 HorizontalResolution;
UINT32 VerticalResolution;
UINTN StringX;
UINTN StringY;
UINTN FontSize;
CHAR16 CompletionString[10];
GraphicsOutput = NULL;
Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput);
if (EFI_ERROR (Status)) {
return Status;
}
HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
FontSize = VerticalResolution * PcdGet32 (PcdL05ProgressCompletionFontSizePercent) / 100;
StringX = HorizontalResolution * PcdGet32 (PcdL05ProgressCompletionHorizontalPercent) / 100;
StringY = VerticalResolution * PcdGet32 (PcdL05ProgressCompletionVerticalPercent) / 100;
ZeroMem (CompletionString, sizeof (CompletionString));
UnicodeSPrint (
CompletionString,
sizeof (CompletionString),
L"%d%% ",
Completion
);
L05PrintStrToImage (
StringX,
StringY,
CompletionString,
FontSize,
PcdGet32 (PcdL05ProgressCompletionForegroundColorValue),
PcdGet32 (PcdL05ProgressCompletionBackgroundColorValue),
0
);
return Status;
}
/**
Scaling refers to the resizing of a digital image.
@param BltScaling Pointer to Blt buffer for scaling image.
@param BltScalingSize Size of Blt buffer for scaling image.
@param Blt Pointer to Blt buffer for original image.
@param BltSize Size of Blt buffer for original image.
@param BltScalingWidth Width of scaling image in pixels.
@param BltScalingHeight Height of scaling image in pixels.
@param BltWidth Width of original image in pixels.
@param BltHeight Height of original image in pixels.
@param IsEdgeProcess Is need Edge Process.
@retval EFI_SUCCESS The operation completed successfully.
@retval Others An unexpected error occurred.
**/
EFI_STATUS
EFIAPI
L05ImageScaling (
IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltScaling,
IN UINTN BltScalingSize,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt,
IN UINTN BltSize,
IN UINTN BltScalingWidth,
IN UINTN BltScalingHeight,
IN UINTN BltWidth,
IN UINTN BltHeight,
IN BOOLEAN IsEdgeProcess
)
{
UINTN BltScalingWidthZoom;
UINTN BltScalingHeightZoom;
UINTN X;
UINTN Y;
UINTN X1;
UINTN Y1;
if ((BltScaling == NULL) || (Blt == NULL)) {
return EFI_INVALID_PARAMETER;
}
if ((BltScalingSize < (BltScalingWidth * BltScalingHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)))
|| (BltSize < (BltWidth * BltHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)))) {
return EFI_BUFFER_TOO_SMALL;
}
BltScalingWidthZoom = BltScalingWidth * PROCESS_PERCENTAGE_VALUE / BltWidth;
BltScalingHeightZoom = BltScalingHeight * PROCESS_PERCENTAGE_VALUE / BltHeight;
//
// Avoid Zoom value is 0, that will make processing mistaken.
//
BltScalingWidthZoom = BltScalingWidthZoom != 0 ? BltScalingWidthZoom : 1;
BltScalingHeightZoom = BltScalingHeightZoom != 0 ? BltScalingHeightZoom : 1;
//
// Image Scaling
//
for (Y1 = 0; Y1 < BltScalingHeight ; Y1++) {
for (X1 = 0; X1 < BltScalingWidth; X1++) {
X = X1 * PROCESS_PERCENTAGE_VALUE / BltScalingWidthZoom;
Y = Y1 * PROCESS_PERCENTAGE_VALUE / BltScalingHeightZoom;
if (IsEdgeProcess) {
if ((X1 < BltScalingHeight)) {
//
// Keep the edge ratio of the picture.
// The height ratio will not change, so use height ratio to keep the edge ratio of the picture.
//
X = X1 * PROCESS_PERCENTAGE_VALUE / BltScalingHeightZoom;
} else if (X < (BltScalingHeight * PROCESS_PERCENTAGE_VALUE / BltScalingHeightZoom)) {
//
// When the X is less than pixel of the keep front edge.
// Set X to last pixel of the keep front edge to avoid picture distortion.
//
X = BltScalingHeight * PROCESS_PERCENTAGE_VALUE / BltScalingHeightZoom;
}
if ((X1 > BltScalingHeight)) {
if ((X1 > BltScalingWidth - BltScalingHeight)) {
//
// Keep the edge ratio of the picture.
// The height ratio will not change, so use height ratio to keep the edge ratio of the picture.
//
X = BltWidth - ((BltScalingWidth - X1) * PROCESS_PERCENTAGE_VALUE / BltScalingHeightZoom);
} else if (X > BltWidth - (BltScalingHeight * PROCESS_PERCENTAGE_VALUE / BltScalingHeightZoom)) {
//
// When the X is greater than pixel of the keep back edge.
// Set X to first pixel of the keep back edge to avoid picture distortion.
//
X = BltWidth - (BltScalingHeight * PROCESS_PERCENTAGE_VALUE / BltScalingHeightZoom);
}
}
}
//
// Avoid source of pixel is out of original image range.
//
if ((X < BltWidth) && (Y < BltHeight)) {
BltScaling[Y1 * BltScalingWidth + X1].Red = Blt[Y * BltWidth + X].Red;
BltScaling[Y1 * BltScalingWidth + X1].Green = Blt[Y * BltWidth + X].Green;
BltScaling[Y1 * BltScalingWidth + X1].Blue = Blt[Y * BltWidth + X].Blue;
} else {
BltScaling[Y1 * BltScalingWidth + X1].Red = BltScaling[Y1 * BltScalingWidth + X1 - 1].Red;
BltScaling[Y1 * BltScalingWidth + X1].Green = BltScaling[Y1 * BltScalingWidth + X1 - 1].Green;
BltScaling[Y1 * BltScalingWidth + X1].Blue = BltScaling[Y1 * BltScalingWidth + X1 - 1].Blue;
}
}
}
return EFI_SUCCESS;
}
/**
Paint Progress Bar by percentage of progressing.
@param[in] ProgressBarType Input progress bar type.
@param[in] DestinationX The X coordinate of the destination for BltOperation.
@param[in] DestinationY The Y coordinate of the destination for BltOperation.
@param[in] BltPixelWidth Width of scaling image in pixels.
@param[in] BltPixelHeight Height of scaling image in pixels.
@retval EFI_SUCCESS The operation completed successfully.
@retval Others An unexpected error occurred.
**/
EFI_STATUS
PaintProgressBar (
IN UINTN ProgressBarType,
IN UINTN DestinationX,
IN UINTN DestinationY,
IN UINTN BltPixelWidth,
IN UINTN BltPixelHeight
)
{
EFI_STATUS Status;
UINT8 *ImageData;
UINTN ImageSize;
VOID *Blt;
UINTN BltSize;
VOID *BltScaling;
UINTN BltScalingSize;
UINTN PixelHeight;
UINTN PixelWidth;
BOOLEAN HasAlphaChannel;
TGA_FORMAT TgaFormate;
UINTN MinVerticalPixles;
if (mTgaDecoder == NULL) {
return EFI_UNSUPPORTED;
}
if (ProgressBarType == PROGRESS_BOARD) {
ImageData = mProgressBoardTga;
ImageSize = sizeof (mProgressBoardTga);
} else if (ProgressBarType == PROGRESS_FULL_BAR) {
ImageData = mProgressFullBarTga;
ImageSize = sizeof (mProgressFullBarTga);
} else {
ImageData = mProgressBarTga;
ImageSize = sizeof (mProgressBarTga);
}
BltScaling = NULL;
Blt = NULL;
BltSize = 0;
//
// Decode Image by TGA
//
Status = mTgaDecoder->DecodeImage (
mTgaDecoder,
ImageData,
ImageSize,
(UINT8 **) &Blt,
&BltSize,
&PixelHeight,
&PixelWidth,
&TgaFormate,
&HasAlphaChannel
);
if (EFI_ERROR (Status)) {
goto Done;
}
//
// When BltPixelHeight is 0, will keep the aspect ratio of progress bar border's image.
//
if (ProgressBarType == PROGRESS_BOARD) {
if (BltPixelHeight == 0) {
BltPixelHeight = BltPixelWidth * PROCESS_PERCENTAGE_VALUE / (PixelWidth * PROCESS_PERCENTAGE_VALUE / PixelHeight);
}
//
// Make sure BltPixelHeight is not less than edge pixel.
//
MinVerticalPixles = PixelHeight;
mBltPixelHeight = BltPixelHeight < MinVerticalPixles ? MinVerticalPixles : BltPixelHeight;
}
//
// Allocate blt scaling Buffer.
//
BltScalingSize = mBltPixelHeight * BltPixelWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
BltScaling = AllocateZeroPool (BltScalingSize);
if (BltScaling == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
//
// Scaling image
//
Status = L05ImageScaling (
(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltScaling,
BltScalingSize,
(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) Blt,
BltSize,
BltPixelWidth,
mBltPixelHeight,
PixelWidth,
PixelHeight,
TRUE
);
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Paint Scaling image
//
Status = mGop->Blt (
mGop,
BltScaling,
EfiBltBufferToVideo,
0,
0,
DestinationX,
DestinationY,
BltPixelWidth,
mBltPixelHeight,
BltPixelWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
);
Done:
if (Blt != NULL) {
FreePool (Blt);
}
if (BltScaling != NULL) {
FreePool (BltScaling);
}
return Status;
}
/**
Paint progress bar percentage by GUID of progress bar image.
This function will init parameter for paint progress bar.
@param[in] ProgressBarType Input progress bar type.
@param[in] Percentage Percentage of progressing.
@retval EFI_SUCCESS The operation completed successfully.
@retval Others An unexpected error occurred.
**/
EFI_STATUS
PaintProgressBarPercentage (
IN UINTN ProgressBarType,
IN UINTN Completion
)
{
EFI_STATUS Status;
UINTN ImageX;
UINTN ImageY;
UINTN TotalBarWidth;
UINTN BltPixelWidth;
//
// L05 update bring the Progress Bar position & width.
//
ImageX = mGop->Mode->Info->HorizontalResolution * PcdGet32 (PcdL05ProgressBarHorizontalPercent) / PROCESS_PERCENTAGE_VALUE;
ImageY = mGop->Mode->Info->VerticalResolution * PcdGet32 (PcdL05ProgressBarVerticalPercent) / PROCESS_PERCENTAGE_VALUE;
TotalBarWidth = mGop->Mode->Info->HorizontalResolution * PcdGet32 (PcdL05ProgressBarWidthPercent) / PROCESS_PERCENTAGE_VALUE;
BltPixelWidth = TotalBarWidth * Completion / PROCESS_PERCENTAGE_VALUE;
if (ProgressBarType == PROGRESS_BAR && Completion == PROCESS_PERCENTAGE_VALUE) {
ProgressBarType = PROGRESS_FULL_BAR;
}
if (ProgressBarType != PROGRESS_BOARD) {
//
// Paint progress percentage.
//
ProgressBarPercentage (Completion);
}
Status = PaintProgressBar (ProgressBarType, ImageX, ImageY, BltPixelWidth, 0);
return Status;
}
/**
Initialize progress bar related functions and display progress bar background for strating to display progress bar.
@retval EFI_SUCESS Initialize progress bar successfully.
@return Other Any progress bar related functions cannot be found.
**/
EFI_STATUS
InitProgressBar (
VOID
)
{
EFI_STATUS Status;
if (mGop == NULL) {
Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &mGop);
if (EFI_ERROR (Status)) {
return Status;
}
}
if (mTgaDecoder == NULL) {
Status = gBS->LocateProtocol (&gEfiTgaDecoderProtocolGuid, NULL, (VOID **) &mTgaDecoder);
if (EFI_ERROR (Status)) {
return Status;
}
}
Status = PaintProgressBarPercentage (PROGRESS_BOARD, PROCESS_PERCENTAGE_VALUE);
return Status;
}
/**
Function to display progress bar to reflect current completion progress of the firmware update.
@param Completion A value between 1 and 100 indicating the current completion progress of the firmware update.
@retval EFI_SUCCESS The operation completed successfully.
@retval Others An unexpected error occurred.
**/
EFI_STATUS
EFIAPI
L05ProgressBar (
IN UINTN Completion
)
{
EFI_STATUS Status;
if (PcdGetBool (PcdL05BiosUpdateUiExtendFwUpdateFlag)) {
//
// Support extend FW update.
//
if (!PcdGetBool (PcdL05BiosUpdateUiExtendFwUpdateStartFlag)) {
//
// BIOS update.
// Calculate percent of completion for BIOS update.
//
Completion = Completion * (100 - PcdGet32 (PcdL05BiosUpdateUiExtendFwUpdateUsedPercent)) / 100;
} else {
//
// Extend FW update.
// Calculate percent of completion for extend FW update.
//
Completion = (100 - PcdGet32 (PcdL05BiosUpdateUiExtendFwUpdateUsedPercent)) + Completion * PcdGet32 (PcdL05BiosUpdateUiExtendFwUpdateUsedPercent) / 100;
}
}
if (mCompletion > Completion) {
InitProgressBar ();
}
//
// Avoid repeat to paint progress bar so return directly if the compltion isn't changed.
//
if (mCompletion == Completion) {
return EFI_SUCCESS;
}
mCompletion = Completion;
Status = PaintProgressBarPercentage (PROGRESS_BAR, Completion);
return Status;
}