public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Gerd Hoffmann" <kraxel@redhat.com>
To: devel@edk2.groups.io
Cc: Gerd Hoffmann <kraxel@redhat.com>,
	Jordan Justen <jordan.l.justen@intel.com>,
	Min Xu <min.m.xu@intel.com>, Jiewen Yao <jiewen.yao@intel.com>,
	Julien Grall <julien@xen.org>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Brijesh Singh <brijesh.singh@amd.com>,
	James Bottomley <jejb@linux.ibm.com>,
	Erdem Aktas <erdemaktas@google.com>,
	Pawel Polawski <ppolawsk@redhat.com>,
	Anthony Perard <anthony.perard@citrix.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>
Subject: [PATCH v2 4/5] OvmfPkg/QemuVideoDxe: factor out QemuVideoBochsAddMode
Date: Mon, 17 Jan 2022 10:58:16 +0100	[thread overview]
Message-ID: <20220117095817.1964424-5-kraxel@redhat.com> (raw)
In-Reply-To: <20220117095817.1964424-1-kraxel@redhat.com>

Add helper function to add a video mode to the list of modes.
Move code.  Minor debug logging tweaks, no other functional
change.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/QemuVideoDxe/Initialize.c | 77 +++++++++++++++++++------------
 1 file changed, 47 insertions(+), 30 deletions(-)

diff --git a/OvmfPkg/QemuVideoDxe/Initialize.c b/OvmfPkg/QemuVideoDxe/Initialize.c
index 2b174d13faf2..8c5c9176ad21 100644
--- a/OvmfPkg/QemuVideoDxe/Initialize.c
+++ b/OvmfPkg/QemuVideoDxe/Initialize.c
@@ -245,16 +245,53 @@ STATIC QEMU_VIDEO_BOCHS_MODES  QemuVideoBochsModes[] = {
 #define QEMU_VIDEO_BOCHS_MODE_COUNT \
   (ARRAY_SIZE (QemuVideoBochsModes))
 
+STATIC
+VOID
+QemuVideoBochsAddMode (
+  QEMU_VIDEO_PRIVATE_DATA  *Private,
+  UINT32                   AvailableFbSize,
+  UINT32                   Width,
+  UINT32                   Height
+  )
+{
+  QEMU_VIDEO_MODE_DATA  *ModeData = Private->ModeData + Private->MaxMode;
+  UINTN                 RequiredFbSize;
+
+  RequiredFbSize = (UINTN)Width * Height * 4;
+  if (RequiredFbSize > AvailableFbSize) {
+    DEBUG ((
+      DEBUG_INFO,
+      "Skipping Bochs Mode %dx%d, 32-bit (not enough vram)\n",
+      Width,
+      Height
+      ));
+    return;
+  }
+
+  ModeData->InternalModeIndex    = (UINT32)Private->MaxMode;
+  ModeData->HorizontalResolution = Width;
+  ModeData->VerticalResolution   = Height;
+  ModeData->ColorDepth           = 32;
+  DEBUG ((
+    DEBUG_INFO,
+    "Adding Bochs Internal Mode %d: %dx%d, %d-bit\n",
+    ModeData->InternalModeIndex,
+    ModeData->HorizontalResolution,
+    ModeData->VerticalResolution,
+    ModeData->ColorDepth
+    ));
+
+  Private->MaxMode++;
+}
+
 EFI_STATUS
 QemuVideoBochsModeSetup (
   QEMU_VIDEO_PRIVATE_DATA  *Private,
   BOOLEAN                  IsQxl
   )
 {
-  UINT32                  AvailableFbSize;
-  UINT32                  Index;
-  QEMU_VIDEO_MODE_DATA    *ModeData;
-  QEMU_VIDEO_BOCHS_MODES  *VideoMode;
+  UINT32  AvailableFbSize;
+  UINT32  Index;
 
   //
   // Fetch the available framebuffer size.
@@ -343,34 +380,14 @@ QemuVideoBochsModeSetup (
     return EFI_OUT_OF_RESOURCES;
   }
 
-  ModeData  = Private->ModeData;
-  VideoMode = &QemuVideoBochsModes[0];
   for (Index = 0; Index < QEMU_VIDEO_BOCHS_MODE_COUNT; Index++) {
-    UINTN  RequiredFbSize;
-
-    RequiredFbSize = (UINTN)VideoMode->Width * VideoMode->Height * 4;
-    if (RequiredFbSize <= AvailableFbSize) {
-      ModeData->InternalModeIndex    = Index;
-      ModeData->HorizontalResolution = VideoMode->Width;
-      ModeData->VerticalResolution   = VideoMode->Height;
-      ModeData->ColorDepth           = 32;
-      DEBUG ((
-        DEBUG_INFO,
-        "Adding Mode %d as Bochs Internal Mode %d: %dx%d, %d-bit\n",
-        (INT32)(ModeData - Private->ModeData),
-        ModeData->InternalModeIndex,
-        ModeData->HorizontalResolution,
-        ModeData->VerticalResolution,
-        ModeData->ColorDepth
-        ));
-
-      ModeData++;
-    }
-
-    VideoMode++;
+    QemuVideoBochsAddMode (
+      Private,
+      AvailableFbSize,
+      QemuVideoBochsModes[Index].Width,
+      QemuVideoBochsModes[Index].Height
+      );
   }
 
-  Private->MaxMode = ModeData - Private->ModeData;
-
   return EFI_SUCCESS;
 }
-- 
2.34.1


  parent reply	other threads:[~2022-01-17  9:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17  9:58 [PATCH v2 0/5] OvmfPkg/QemuVideoDxe: pick up display resolution settings from the host Gerd Hoffmann
2022-01-17  9:58 ` [PATCH v2 1/5] OvmfPkg: add PcdVideoResolutionSource Gerd Hoffmann
2022-01-17  9:58 ` [PATCH v2 2/5] OvmfPkg/QemuVideoDxe: simplify InitializeBochsGraphicsMode Gerd Hoffmann
2022-01-17  9:58 ` [PATCH v2 3/5] OvmfPkg/QemuVideoDxe: drop QEMU_VIDEO_BOCHS_MODES->ColorDepth Gerd Hoffmann
2022-01-17  9:58 ` Gerd Hoffmann [this message]
2022-01-17  9:58 ` [PATCH v2 5/5] OvmfPkg/QemuVideoDxe: parse edid blob, detect display resolution Gerd Hoffmann
2022-01-29 17:08 ` [PATCH v2 0/5] OvmfPkg/QemuVideoDxe: pick up display resolution settings from the host Ard Biesheuvel

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=20220117095817.1964424-5-kraxel@redhat.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