From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smarthost01a.ixn.mail.zen.net.uk (smarthost01a.ixn.mail.zen.net.uk [212.23.1.20])
 by mx.groups.io with SMTP id smtpd.web10.8689.1671180995443287744
 for <devel@edk2.groups.io>;
 Fri, 16 Dec 2022 00:56:36 -0800
Authentication-Results: mx.groups.io;
 dkim=missing; spf=permerror, err=parse error for token &{10 18 sdn.klaviyomail.com}: permanent DNS error (domain: starlabs.systems, ip: 212.23.1.20, mailfrom: sean@starlabs.systems)
Received: from [51.148.147.4] (helo=starbook..)
	by smarthost01a.ixn.mail.zen.net.uk with esmtp (Exim 4.90_1)
	(envelope-from <sean@starlabs.systems>)
	id 1p66W5-0004gn-Qc; Fri, 16 Dec 2022 08:56:29 +0000
From: "Sean Rhodes" <sean@starlabs.systems>
To: devel@edk2.groups.io
Cc: Sean Rhodes <sean@starlabs.systems>,
	Zhichao Gao <zhichao.gao@intel.com>,
	Ray Ni <ray.ni@intel.com>,
	Jian J Wang <jian.j.wang@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>
Subject: [PATCH] MdeModulePkg/Logo: Add a PCD to control the position of the Logo
Date: Fri, 16 Dec 2022 08:56:28 +0000
Message-Id: <7c6fbeb2fda06a9af82d61965c4294194b4f12b3.1671180987.git.sean@starlabs.systems>
X-Mailer: git-send-email 2.37.2
MIME-Version: 1.0
X-Originating-smarthost01a-IP: [51.148.147.4]
Feedback-ID: 51.148.147.4
Content-Transfer-Encoding: quoted-printable

When set to true, the Logo is positioned according to the BGRT
specification, 38.2% from the top of the screen. When set to false,
no behaviour is changed and the logo is positioned centrally.

Cc: Zhichao Gao <zhichao.gao@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
---
 MdeModulePkg/Logo/Logo.c      | 28 +++++++++++++++++++++++++++-
 MdeModulePkg/Logo/LogoDxe.inf |  4 ++++
 MdeModulePkg/MdeModulePkg.dec |  6 ++++++
 MdeModulePkg/MdeModulePkg.uni |  6 ++++++
 4 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Logo/Logo.c b/MdeModulePkg/Logo/Logo.c
index 8ab874d2da..96e34b2011 100644
--- a/MdeModulePkg/Logo/Logo.c
+++ b/MdeModulePkg/Logo/Logo.c
@@ -13,6 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Protocol/HiiPackageList.h>=0D
 #include <Library/UefiBootServicesTableLib.h>=0D
 #include <Library/DebugLib.h>=0D
+#include <Library/PcdLib.h>=0D
 =0D
 typedef struct {=0D
   EFI_IMAGE_ID                             ImageId;=0D
@@ -51,12 +52,14 @@ GetImage (
   IN     EDKII_PLATFORM_LOGO_PROTOCOL        *This,=0D
   IN OUT UINT32                              *Instance,=0D
   OUT EFI_IMAGE_INPUT                        *Image,=0D
+  EFI_GRAPHICS_OUTPUT_PROTOCOL               *GraphicsOutput,=0D
   OUT EDKII_PLATFORM_LOGO_DISPLAY_ATTRIBUTE  *Attribute,=0D
   OUT INTN                                   *OffsetX,=0D
   OUT INTN                                   *OffsetY=0D
   )=0D
 {=0D
-  UINT32  Current;=0D
+  UINT32      Current;=0D
+  EFI_STATUS  Status;=0D
 =0D
   if ((Instance =3D=3D NULL) || (Image =3D=3D NULL) ||=0D
       (Attribute =3D=3D NULL) || (OffsetX =3D=3D NULL) || (OffsetY =3D=3D =
NULL))=0D
@@ -69,6 +72,29 @@ GetImage (
     return EFI_NOT_FOUND;=0D
   }=0D
 =0D
+  if (PcdGetBool (PcdFollowMicrosoftRecommended)) {=0D
+    //=0D
+    // Get current video resolution and text mode=0D
+    //=0D
+    Status =3D gBS->HandleProtocol (=0D
+                    gST->ConsoleOutHandle,=0D
+                    &gEfiGraphicsOutputProtocolGuid,=0D
+                    (VOID **)&GraphicsOutput=0D
+                    );=0D
+    if (!EFI_ERROR (Status)) {=0D
+      //=0D
+      // Center of LOGO is in the vertical position 38.2% when PcdBootLogo=
OnlyEnable is TRUE=0D
+      // Y =3D (VerticalResolution - LogoHeight) / 2=0D
+      // Y' =3D VerticalResolution * 0.382 - LogoHeight * 0.5=0D
+      // OffsetY + Y =3D Y'=0D
+      // OffsetY =3D Y' - Y =3D -0.118 * VerticalResolution=0D
+      //=0D
+      *Attribute =3D EdkiiPlatformLogoDisplayAttributeCenter;=0D
+      *OffsetX   =3D 0;=0D
+      *OffsetY   =3D -118 * (INTN)GraphicsOutput->Mode->Info->VerticalReso=
lution / 1000;=0D
+    }=0D
+  }=0D
+=0D
   (*Instance)++;=0D
   *Attribute =3D mLogos[Current].Attribute;=0D
   *OffsetX   =3D mLogos[Current].OffsetX;=0D
diff --git a/MdeModulePkg/Logo/LogoDxe.inf b/MdeModulePkg/Logo/LogoDxe.inf
index 41215d25d8..ce29950089 100644
--- a/MdeModulePkg/Logo/LogoDxe.inf
+++ b/MdeModulePkg/Logo/LogoDxe.inf
@@ -41,6 +41,7 @@
   UefiBootServicesTableLib=0D
   UefiDriverEntryPoint=0D
   DebugLib=0D
+  PcdLib=0D
 =0D
 [Protocols]=0D
   gEfiHiiDatabaseProtocolGuid        ## CONSUMES=0D
@@ -48,6 +49,9 @@
   gEfiHiiPackageListProtocolGuid     ## PRODUCES CONSUMES=0D
   gEdkiiPlatformLogoProtocolGuid     ## PRODUCES=0D
 =0D
+[Pcd]=0D
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFollowMicrosoftRecommended ## CONSUMES=
=0D
+=0D
 [Depex]=0D
   gEfiHiiDatabaseProtocolGuid AND=0D
   gEfiHiiImageExProtocolGuid=0D
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index be5e829ca9..c8bb51df3b 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -2102,6 +2102,12 @@
   # @Prompt The shared bit mask when Intel Tdx is enabled.=0D
   gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask|0x0|UINT64|0x10000025=
=0D
 =0D
+  ## This PCD sets the position of the Boot Logo.=0D
+  #   TRUE  - The Logo is positioned following the recommendations from Mi=
crosoft.=0D
+  #   FALSE - The logo is positioned in the center of the screen.=0D
+  # @ Prompt This position of the boot logo=0D
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFollowMicrosoftRecommended|FALSE|BOOLE=
AN|0x10000026=0D
+=0D
 [PcdsPatchableInModule]=0D
   ## Specify memory size with page number for PEI code when=0D
   #  Loading Module at Fixed Address feature is enabled.=0D
diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni
index 33ce9f6198..09c1ac1cc1 100644
--- a/MdeModulePkg/MdeModulePkg.uni
+++ b/MdeModulePkg/MdeModulePkg.uni
@@ -1338,3 +1338,9 @@
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdPcieResizableBarSupport_HELP=
 #language en-US "Indicates if the PCIe Resizable BAR Capability Supported.=
<BR><BR>\n"=0D
                                                                           =
                  "TRUE  - PCIe Resizable BAR Capability is supported.<BR>\=
n"=0D
                                                                           =
                  "FALSE - PCIe Resizable BAR Capability is not supported.<=
BR>"=0D
+=0D
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdFollowMicrosoftRecommended_P=
ROMPT #language en-US "The position of the Boot Logo"=0D
+=0D
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdFollowMicrosoftRecommend_HEL=
P   #language en-US "Sets the position of the Logo. When set to true, the L=
ogo is positioned following the recommendations"=0D
+                                                                          =
                   " from Microsoft, 38.2% from the top of the screen."=0D
+=0D
--=20
2.37.2