public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Michael D Kinney <michael.d.kinney@intel.com>
To: edk2-devel@lists.01.org
Cc: Sean Brogan <sean.brogan@microsoft.com>,
	Star Zeng <star.zeng@intel.com>, Eric Dong <eric.dong@intel.com>
Subject: [Patch 2/9] MdeModulePkg: Add DisplayUpdateProgressLib instances
Date: Wed,  4 Apr 2018 13:25:47 -0700	[thread overview]
Message-ID: <20180404202554.9568-3-michael.d.kinney@intel.com> (raw)
In-Reply-To: <20180404202554.9568-1-michael.d.kinney@intel.com>

https://bugzilla.tianocore.org/show_bug.cgi?id=801

Based on content from the following branch/commits:
https://github.com/Microsoft/MS_UEFI/tree/share/MsCapsuleSupport

Add DisplayUpdateProgressLib instances for text consoles
and graphical consoles.

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
---
 .../DisplayUpdateProgressGraphicsLib.c             | 475 +++++++++++++++++++++
 .../DisplayUpdateProgressGraphicsLib.inf           |  60 +++
 .../DisplayUpdateProgressGraphicsLib.uni           |  18 +
 .../DisplayUpdateProgressTextLib.c                 | 142 ++++++
 .../DisplayUpdateProgressTextLib.inf               |  53 +++
 .../DisplayUpdateProgressTextLib.uni               |  18 +
 MdeModulePkg/MdeModulePkg.dsc                      |   3 +
 7 files changed, 769 insertions(+)
 create mode 100644 MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.c
 create mode 100644 MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.inf
 create mode 100644 MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.uni
 create mode 100644 MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.c
 create mode 100644 MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.inf
 create mode 100644 MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.uni

diff --git a/MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.c b/MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.c
new file mode 100644
index 0000000000..007522cea0
--- /dev/null
+++ b/MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.c
@@ -0,0 +1,475 @@
+/**  @file
+  Provides services to display completion progress of a firmware update on a
+  graphical console that supports the Graphics Output Protocol.
+
+  Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
+  Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions are met:
+  1. Redistributions of source code must retain the above copyright notice,
+  this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright notice,
+  this list of conditions and the following disclaimer in the documentation
+  and/or other materials provided with the distribution.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+**/
+
+#include <PiDxe.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/GraphicsOutput.h>
+#include <Protocol/BootLogo2.h>
+
+//
+// Values in percent of of logo height.
+//
+#define LOGO_BOTTOM_PADDING    20
+#define PROGRESS_BLOCK_HEIGHT  10
+
+//
+// Graphics Output Protocol instance to display progress bar
+//
+EFI_GRAPHICS_OUTPUT_PROTOCOL  *mGop = NULL;
+
+//
+// Set to 100 percent so it is reset on first call.
+//
+UINTN mPreviousProgress = 100;
+
+//
+// Display coordinates for the progress bar.
+//
+UINTN  mStartX = 0;
+UINTN  mStartY = 0;
+
+//
+// Width and height of the progress bar.
+//
+UINTN  mBlockWidth  = 0;
+UINTN  mBlockHeight = 0;
+
+//
+// GOP bitmap of the progress bar. Initialized on every new progress of 100%
+//
+EFI_GRAPHICS_OUTPUT_BLT_PIXEL  *mBlockBitmap;
+
+//
+// GOP bitmap of the progress bar backround.  Initialized once.
+//
+EFI_GRAPHICS_OUTPUT_BLT_PIXEL  *mProgressBarBackground;
+
+//
+// Default mask used to detect the left, right , top, and bottom of logo.  Only
+// green and blue pixels are used for logo detection.
+//
+const EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION  mLogoDetectionColorMask = {
+  {
+    0xFF,  // Blue
+    0xFF,  // Green
+    0x00,  // Red
+    0x00   // Reserved
+  }
+};
+
+//
+// Background color of progress bar.  Grey.
+//
+const EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION  mProgressBarBackgroundColor = {
+  {
+    0x80,  // Blue
+    0x80,  // Green
+    0x80,  // Red
+    0x00   // Reserved
+  }
+};
+
+//
+// Default color of progress completion.  White.
+//
+const EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION  mProgressBarDefaultColor = {
+  {
+    0xFF,  // Blue
+    0xFF,  // Green
+    0xFF,  // Red
+    0x00   // Reserved
+  }
+};
+
+//
+// Set to TRUE if a valid Graphics Output Protocol is found and the progress
+// bar fits under the boot logo using the current graphics mode.
+//
+BOOLEAN mGraphicsGood = FALSE;
+
+/*
+  Internal function used to find the bounds of the white logo (on black or
+  red background).
+
+  These bounds are then computed to find the block size, 0%, 100%, etc.
+
+*/
+VOID
+FindDim (
+   VOID
+  )
+{
+  EFI_STATUS                           Status;
+  INTN                                 LogoX;
+  INTN                                 LogoStartX;
+  INTN                                 LogoEndX;
+  INTN                                 LogoY;
+  INTN                                 LogoStartY;
+  INTN                                 LogoEndY;
+  UINTN                                OffsetX;     // Logo screen coordinate
+  UINTN                                OffsetY;     // Logo screen coordinate
+  UINTN                                Width;       // Width of logo in pixels
+  UINTN                                Height;      // Height of logo in pixels
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL        *Logo;
+  EDKII_BOOT_LOGO2_PROTOCOL            *BootLogo;
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION  *Pixel;
+
+  Logo     = NULL;
+  BootLogo = NULL;
+
+  //
+  // Return if a Graphics Output Protocol ha snot been found.
+  //
+  if (mGop == NULL) {
+    DEBUG ((DEBUG_ERROR, "No GOP found.  No progress bar support. \n"));
+    return;
+  }
+
+  //
+  // Get boot logo protocol so we know where on the screen to grab
+  //
+  Status = gBS->LocateProtocol (
+                  &gEdkiiBootLogo2ProtocolGuid,
+                  NULL,
+                  (VOID **)&BootLogo
+                  );
+  if ((BootLogo == NULL) || (EFI_ERROR (Status))) {
+    DEBUG ((DEBUG_ERROR, "Failed to locate gEdkiiBootLogo2ProtocolGuid.  No Progress bar support. \n", Status));
+    return;
+  }
+
+  //
+  // Get logo location and size
+  //
+  Status = BootLogo->GetBootLogo (
+                       BootLogo,
+                       &Logo,
+                       &OffsetX,
+                       &OffsetY,
+                       &Width,
+                       &Height
+                       );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "Failed to Get Boot Logo Status = %r.  No Progress bar support. \n", Status));
+    return;
+  }
+
+  //
+  // Within logo buffer find where the actual logo starts/ends
+  //
+  LogoEndX = 0;
+  LogoEndY = 0;
+
+  //
+  // Find left side of logo in logo coordinates
+  //
+  for (LogoX = 0, LogoStartX = Width; LogoX < LogoStartX; LogoX++) {
+    Pixel = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *)(Logo + LogoX);
+    for (LogoY = 0; LogoY < (INTN)Height; LogoY++) {
+      if ((Pixel->Raw & mLogoDetectionColorMask.Raw) != 0x0) {
+        LogoStartX = LogoX;
+        //
+        // For loop searches from right side back to this column.
+        //
+        LogoEndX = LogoX;
+        DEBUG ((DEBUG_INFO, "StartX found at (%d, %d) Color is: 0x%X \n", LogoX, LogoY, Pixel->Raw));
+        break;
+      }
+      Pixel = Pixel + Width;
+    }
+  }
+
+  //
+  // Find right side of logo
+  //
+  for (LogoX = Width - 1; LogoX >= LogoEndX; LogoX--) {
+    Pixel = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *)(Logo + LogoX);
+    for (LogoY = 0; LogoY < (INTN)Height; LogoY++) {
+      if ((Pixel->Raw & mLogoDetectionColorMask.Raw) != 0x0) {
+        LogoEndX = LogoX;
+        DEBUG ((DEBUG_INFO, "EndX found at (%d, %d) Color is: 0x%X \n", LogoX, LogoY, Pixel->Raw));
+        break;
+      }
+      Pixel = Pixel + Width;
+    }
+  }
+
+  //
+  // Compute mBlockWidth
+  //
+  mBlockWidth = ((LogoEndX - LogoStartX) + 99) / 100;
+
+  //
+  // Adjust mStartX based on block width so it is centered under logo
+  //
+  mStartX = LogoStartX + OffsetX - (((mBlockWidth * 100) - (LogoEndX - LogoStartX)) / 2);
+  DEBUG ((DEBUG_INFO, "mBlockWidth set to 0x%X\n", mBlockWidth));
+  DEBUG ((DEBUG_INFO, "mStartX set to 0x%X\n", mStartX));
+
+  //
+  // Find the top of the logo
+  //
+  for (LogoY = 0, LogoStartY = Height; LogoY < LogoStartY; LogoY++) {
+    Pixel = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *)(Logo + (Width * LogoY));
+    for (LogoX = 0; LogoX < (INTN)Width; LogoX++) {
+      //not black or red
+      if ((Pixel->Raw & mLogoDetectionColorMask.Raw) != 0x0) {
+        LogoStartY = LogoY;
+        LogoEndY = LogoY; //for next loop will search from bottom side back to this row.
+        DEBUG ((DEBUG_INFO, "StartY found at (%d, %d) Color is: 0x%X \n", LogoX, LogoY, Pixel->Raw));
+        break;
+      }
+      Pixel++;
+    }
+  }
+
+  //
+  // Find the bottom of the logo
+  //
+  for (LogoY = Height - 1; LogoY >= LogoEndY; LogoY--) {
+    Pixel = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *)(Logo + (Width * LogoY));
+    for (LogoX = 0; LogoX < (INTN)Width; LogoX++) {
+      if ((Pixel->Raw & mLogoDetectionColorMask.Raw) != 0x0) {
+        LogoEndY = LogoY;
+        DEBUG ((DEBUG_INFO, "EndY found at (%d, %d) Color is: 0x%X \n", LogoX, LogoY, Pixel->Raw));
+        break;
+      }
+      Pixel++;
+    }
+  }
+
+  //
+  // Compute bottom padding (distance between logo bottom and progress bar)
+  //
+  mStartY = (((LogoEndY - LogoStartY) * LOGO_BOTTOM_PADDING) / 100) + LogoEndY + OffsetY;
+
+  //
+  // Compute progress bar height
+  //
+  mBlockHeight = (((LogoEndY - LogoStartY) * PROGRESS_BLOCK_HEIGHT) / 100);
+
+  DEBUG ((DEBUG_INFO, "mBlockHeight set to 0x%X\n", mBlockHeight));
+
+  //
+  // Create progress bar background (one time init).
+  //
+  mProgressBarBackground = AllocatePool (mBlockWidth * 100 * mBlockHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
+  if (mProgressBarBackground == NULL) {
+    DEBUG ((DEBUG_ERROR, "Failed to allocate progress bar background\n"));
+    return;
+  }
+
+  //
+  // Fill the progress bar with the background color
+  //
+  SetMem32 (
+    mProgressBarBackground,
+    (mBlockWidth * 100 * mBlockHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)),
+    mProgressBarBackgroundColor.Raw
+    );
+
+  //
+  // Allocate mBlockBitmap
+  //
+  mBlockBitmap = AllocatePool (mBlockWidth * mBlockHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
+  if (mBlockBitmap == NULL) {
+    FreePool (mProgressBarBackground);
+    DEBUG ((DEBUG_ERROR, "Failed to allocate block\n"));
+    return;
+  }
+
+  //
+  // Check screen width and height and make sure it fits.
+  //
+  if ((mBlockHeight > Height) || (mBlockWidth > Width) || (mBlockHeight < 1) || (mBlockWidth < 1)) {
+    DEBUG ((DEBUG_ERROR, "DisplayUpdateProgressLib - Progress - Failed to get valid width and height.\n"));
+    DEBUG ((DEBUG_ERROR, "DisplayUpdateProgressLib - Progress - mBlockHeight: 0x%X  mBlockWidth: 0x%X.\n", mBlockHeight, mBlockWidth));
+    FreePool (mProgressBarBackground);
+    FreePool (mBlockBitmap);
+    return;
+  }
+
+  mGraphicsGood = TRUE;
+}
+
+/**
+  Function indicates the current completion progress of a firmware update.
+  Platform may override with its own specific function.
+
+  @param[in] Completion  A value between 0 and 100 indicating the current
+                         completion progress of a firmware update.  This
+                         value must the the same or higher than previous
+                         calls to this service.  The first call of 0 or a
+                         value of 0 after reaching a value of 100 resets
+                         the progress indicator to 0.
+  @param[in] Color       Color of the progress indicator.  Only used when
+                         Completion is 0 to set the color of the progress
+                         indicator.  If Color is NULL, then the default color
+                         is used.
+
+  @retval EFI_SUCCESS            Progress displayed successfully.
+  @retval EFI_INVALID_PARAMETER  Completion is not in range 0..100.
+  @retval EFI_INVALID_PARAMETER  Completion is less than Completion value from
+                                 a previous call to this service.
+  @retval EFI_NOT_READY          The device used to indicate progress is not
+                                 available.
+**/
+EFI_STATUS
+EFIAPI
+DisplayUpdateProgress (
+  IN UINTN                                Completion,
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION  *Color       OPTIONAL
+  )
+{
+  EFI_STATUS  Status;
+  UINTN       PreX;
+  UINTN       Index;
+
+  //
+  // Check range
+  //
+  if (Completion > 100) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Check to see if this Completion percentage has already been displayed
+  //
+  if (Completion == mPreviousProgress) {
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Find Graphics Output Protocol if not already set.  1 time.
+  //
+  if (mGop == NULL) {
+    Status = gBS->HandleProtocol (
+                    gST->ConsoleOutHandle,
+                    &gEfiGraphicsOutputProtocolGuid,
+                    (VOID**)&mGop
+                    );
+    if (EFI_ERROR (Status)) {
+      Status = gBS->LocateProtocol (&gEfiGraphicsOutputProtocolGuid, NULL, (VOID **)&mGop);
+      if (EFI_ERROR (Status)) {
+        mGop = NULL;
+        DEBUG ((DEBUG_ERROR, "Show Progress Function could not locate GOP.  Status = %r\n", Status));
+        return EFI_NOT_READY;
+      }
+    }
+
+    //
+    // Run once
+    //
+    FindDim ();
+  }
+
+  //
+  // Make sure a valid start, end, and size info are available (find the Logo)
+  //
+  if (!mGraphicsGood) {
+    DEBUG ((DEBUG_INFO, "Graphics Not Good.  Not doing any onscreen visual display\n"));
+    return EFI_NOT_READY;
+  }
+
+  //
+  // Do special init on first call of each progress session
+  //
+  if (mPreviousProgress == 100) {
+    //
+    // Draw progress bar background
+    //
+    mGop->Blt (
+            mGop,
+            mProgressBarBackground,
+            EfiBltBufferToVideo,
+            0,
+            0,
+            mStartX,
+            mStartY,
+            (mBlockWidth * 100),
+            mBlockHeight,
+            0
+            );
+
+    DEBUG ((DEBUG_VERBOSE, "Color is 0x%X\n",
+      (Color == NULL) ? mProgressBarDefaultColor.Raw : Color->Raw
+      ));
+
+    //
+    // Update block bitmap with correct color
+    //
+    SetMem32 (
+      mBlockBitmap,
+      (mBlockWidth * mBlockHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)),
+      (Color == NULL) ? mProgressBarDefaultColor.Raw : Color->Raw
+      );
+
+    //
+    // Clear previous
+    //
+    mPreviousProgress = 0;
+  }
+
+  //
+  // Can not update progress bar if Completion is less than previous
+  //
+  if (Completion < mPreviousProgress) {
+    DEBUG ((DEBUG_WARN, "WARNING: Completion (%d) should not be lesss than Previous (%d)!!!\n", Completion, mPreviousProgress));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  PreX = ((mPreviousProgress * mBlockWidth) + mStartX);
+  for (Index = 0; Index < (Completion - mPreviousProgress); Index++) {
+    //
+    // Show progress by coloring new area
+    //
+    mGop->Blt (
+            mGop,
+            mBlockBitmap,
+            EfiBltBufferToVideo,
+            0,
+            0,
+            PreX,
+            mStartY,
+            mBlockWidth,
+            mBlockHeight,
+            0
+            );
+    PreX += mBlockWidth;
+  }
+
+  mPreviousProgress = Completion;
+
+  return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.inf b/MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.inf
new file mode 100644
index 0000000000..810f13acd9
--- /dev/null
+++ b/MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.inf
@@ -0,0 +1,60 @@
+## @file
+#  Provides services to display completion progress of a firmware update on a
+#  graphical console that supports the Graphics Output Protocol.
+#
+#  Copyright (c) 2016, Microsoft Corporation, All rights reserved.<BR>
+#  Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions are met:
+#  1. Redistributions of source code must retain the above copyright notice,
+#  this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the above copyright notice,
+#  this list of conditions and the following disclaimer in the documentation
+#  and/or other materials provided with the distribution.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+#  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+#  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+#  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+#  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+#  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+##
+
+[Defines]
+  INF_VERSION     = 0x00010005
+  BASE_NAME       = DisplayUpdateProgressGraphicsLib
+  MODULE_UNI_FILE = DisplayUpdateProgressGraphicsLib.uni
+  FILE_GUID       = 319E9E37-B2D6-4699-90F3-B8B72B6D4CBD
+  MODULE_TYPE     = DXE_DRIVER
+  VERSION_STRING  = 1.0
+  LIBRARY_CLASS   = DisplayUpdateProgressLib|DXE_DRIVER UEFI_DRIVER UEFI_APPLICATION
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
+#
+
+[Sources]
+  DisplayUpdateProgressGraphicsLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
+  DebugLib
+  MemoryAllocationLib
+  UefiBootServicesTableLib
+  BaseLib
+  UefiLib
+
+[Protocols]
+  gEfiGraphicsOutputProtocolGuid  # CONSUMES
+  gEdkiiBootLogo2ProtocolGuid     # CONSUMES
diff --git a/MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.uni b/MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.uni
new file mode 100644
index 0000000000..d7da641338
--- /dev/null
+++ b/MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.uni
@@ -0,0 +1,18 @@
+// /** @file
+//  Provides services to display completion progress of a firmware update on a
+//  graphical console that supports the Graphics Output Protocol.
+//
+// Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
+//
+// This program and the accompanying materials
+// are licensed and made available under the terms and conditions of the BSD License
+// which accompanies this distribution. The full text of the license may be found at
+// http://opensource.org/licenses/bsd-license.php
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+//
+// **/
+
+#string STR_MODULE_ABSTRACT     #language en-US  "Provides services to display completion progress of a firmware update on a graphical console that supports the Graphics Output Protocol."
+
+#string STR_MODULE_DESCRIPTION  #language en-US  "Provides services to display completion progress of a firmware update on a graphical console that supports the Graphics Output Protocol."
diff --git a/MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.c b/MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.c
new file mode 100644
index 0000000000..aa849aba2e
--- /dev/null
+++ b/MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.c
@@ -0,0 +1,142 @@
+/**  @file
+  Provides services to display completion progress of a firmware update on a
+  text console.
+
+  Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
+  Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions are met:
+  1. Redistributions of source code must retain the above copyright notice,
+  this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright notice,
+  this list of conditions and the following disclaimer in the documentation
+  and/or other materials provided with the distribution.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+**/
+
+#include <PiDxe.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+//
+// Control Style.  Set to 100 so it is reset on first call.
+//
+UINTN  mPreviousProgress = 100;
+
+/**
+  Function indicates the current completion progress of a firmware update.
+  Platform may override with its own specific function.
+
+  @param[in] Completion  A value between 0 and 100 indicating the current
+                         completion progress of a firmware update.  This
+                         value must the the same or higher than previous
+                         calls to this service.  The first call of 0 or a
+                         value of 0 after reaching a value of 100 resets
+                         the progress indicator to 0.
+  @param[in] Color       Color of the progress indicator.  Only used when
+                         Completion is 0 to set the color of the progress
+                         indicator.  If Color is NULL, then the default color
+                         is used.
+
+  @retval EFI_SUCCESS            Progress displayed successfully.
+  @retval EFI_INVALID_PARAMETER  Completion is not in range 0..100.
+  @retval EFI_INVALID_PARAMETER  Completion is less than Completion value from
+                                 a previous call to this service.
+  @retval EFI_NOT_READY          The device used to indicate progress is not
+                                 available.
+**/
+EFI_STATUS
+EFIAPI
+DisplayUpdateProgress (
+  IN UINTN                                Completion,
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION  *Color       OPTIONAL
+  )
+{
+  UINTN  Foreground;
+  UINTN  Index;
+
+  //
+  // Check range
+  //
+  if (Completion > 100) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Check to see if this Completion percentage has already been displayed
+  //
+  if (Completion == mPreviousProgress) {
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Do special init on first call of each progress session
+  //
+  if (mPreviousProgress == 100) {
+    Print (L"\n");
+
+    //
+    // Convert pixel color to text foreground color
+    //
+    if (Color == NULL) {
+      Foreground = EFI_WHITE;
+    } else {
+      Foreground = EFI_BLACK;
+      if (Color->Pixel.Blue >= 0x40) {
+        Foreground = Foreground | EFI_BLUE;
+      }
+      if (Color->Pixel.Green >= 0x40) {
+        Foreground = Foreground | EFI_GREEN;
+      }
+      if (Color->Pixel.Red >= 0x40) {
+        Foreground = Foreground | EFI_RED;
+      }
+      if (Color->Pixel.Blue >= 0xC0 || Color->Pixel.Green >= 0xC0 || Color->Pixel.Red >= 0xC0) {
+        Foreground = Foreground | EFI_BRIGHT;
+      }
+      if (Foreground == EFI_BLACK) {
+        Foreground = EFI_WHITE;
+      }
+    }
+    gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (Foreground, EFI_BLACK));
+
+    //
+    // Clear previous
+    //
+    mPreviousProgress = 0;
+  }
+
+  //
+  // Can not update progress bar if Completion is less than previous
+  //
+  if (Completion < mPreviousProgress) {
+    DEBUG ((DEBUG_WARN, "WARNING: Completion (%d) should not be lesss than Previous (%d)!!!\n", Completion, mPreviousProgress));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Print (L"\rUpdate Progress - %3d%% ", Completion);
+  for (Index = 0; Index < 50; Index++) {
+    if (Index <= Completion / 2) {
+      Print (L"%c", 0x2588);
+    } else {
+      Print (L"%c", 0x2591);
+    }
+  }
+
+  mPreviousProgress = Completion;
+
+  return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.inf b/MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.inf
new file mode 100644
index 0000000000..b5782dc44c
--- /dev/null
+++ b/MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.inf
@@ -0,0 +1,53 @@
+## @file
+#  Provides services to display completion progress of a firmware update on a
+#  text console.
+#
+#  Copyright (c) 2016, Microsoft Corporation, All rights reserved.<BR>
+#  Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions are met:
+#  1. Redistributions of source code must retain the above copyright notice,
+#  this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the above copyright notice,
+#  this list of conditions and the following disclaimer in the documentation
+#  and/or other materials provided with the distribution.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+#  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+#  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+#  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+#  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+#  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+##
+
+[Defines]
+  INF_VERSION     = 0x00010005
+  BASE_NAME       = DisplayUpdateProgressTextLib
+  MODULE_UNI_FILE = DisplayUpdateProgressTextLib.uni
+  FILE_GUID       = CDEF83AE-1900-4B41-BF47-AAE9BD729CA5
+  MODULE_TYPE     = DXE_DRIVER
+  VERSION_STRING  = 1.0
+  LIBRARY_CLASS   = DisplayUpdateProgressLib|DXE_DRIVER UEFI_DRIVER UEFI_APPLICATION
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
+#
+
+[Sources]
+  DisplayUpdateProgressTextLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  DebugLib
+  UefiBootServicesTableLib
+  UefiLib
diff --git a/MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.uni b/MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.uni
new file mode 100644
index 0000000000..3c783722bc
--- /dev/null
+++ b/MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.uni
@@ -0,0 +1,18 @@
+// /** @file
+//  Provides services to display completion progress of a firmware update on a
+//  text console.
+//
+// Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
+//
+// This program and the accompanying materials
+// are licensed and made available under the terms and conditions of the BSD License
+// which accompanies this distribution. The full text of the license may be found at
+// http://opensource.org/licenses/bsd-license.php
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+//
+// **/
+
+#string STR_MODULE_ABSTRACT     #language en-US  "Provides services to display completion progress of a firmware update on a text console."
+
+#string STR_MODULE_DESCRIPTION  #language en-US  "Provides services to display completion progress of a firmware update on a text console."
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index ec24a50c7d..d122e78266 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -108,6 +108,7 @@ [LibraryClasses]
   CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
   BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf
   SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
+  DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.inf
 
 [LibraryClasses.EBC.PEIM]
   IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf
@@ -327,6 +328,8 @@ [Components]
   MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf
   MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.inf
   MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf
+  MdeModulePkg/Library/DisplayUpdateProgressGraphicsLib/DisplayUpdateProgressGraphicsLib.inf
+  MdeModulePkg/Library/DisplayUpdateProgressTextLib/DisplayUpdateProgressTextLib.inf
 
   MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
   MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf
-- 
2.14.2.windows.3



  parent reply	other threads:[~2018-04-04 20:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-04 20:25 [Patch 0/9] Add DisplayUpdateProgressLib for capsules Michael D Kinney
2018-04-04 20:25 ` [Patch 1/9] MdeModulePkg: Add DisplayUpdateProgressLib class Michael D Kinney
2018-04-04 20:25 ` Michael D Kinney [this message]
2018-04-04 20:25 ` [Patch 3/9] Vlv2Tbl2DevicePkg: Add DisplayUpdateProgressLib mapping Michael D Kinney
2018-04-08  6:12   ` Wei, David
2018-04-04 20:25 ` [Patch 4/9] QuarkPlatformPkg: " Michael D Kinney
2018-04-04 20:25 ` [Patch 5/9] MdeModulePkg/DxeCapsuleLibFmp: Add progress bar support Michael D Kinney
2018-04-04 20:25 ` [Patch 6/9] SignedCapsulePkg/PlatformFlashAccessLib: Add progress API Michael D Kinney
2018-04-04 20:25 ` [Patch 7/9] Vlv2TbltDevicePkg/PlatformFlashAccessLib: " Michael D Kinney
2018-04-08  6:11   ` Wei, David
2018-04-04 20:25 ` [Patch 8/9] QuarkPlatformPkg/PlatformFlashAccessLib: " Michael D Kinney
2018-04-04 20:25 ` [Patch 9/9] SignedCapsulePkg/SystemFirmwareUpdateDxe: Use " Michael D Kinney
2018-04-06 13:55   ` Ard Biesheuvel
2018-04-06 15:29     ` Kinney, Michael D
2018-04-04 20:29 ` [Patch 0/9] Add DisplayUpdateProgressLib for capsules Kinney, Michael D
2018-04-05  0:02 ` Yao, Jiewen
2018-04-05  0:37   ` Kinney, Michael D

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180404202554.9568-3-michael.d.kinney@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox