From 01a6d8366c5c3bf8c52f666a1c302fea035185da Mon Sep 17 00:00:00 2001 From: Joursoir Date: Fri, 25 Mar 2022 18:37:48 +0300 Subject: main: add graphics context --- UefiMonitorTest/UefiMonitorTest.c | 36 ++++++++++++++++++++++++++++++++++++ UefiMonitorTest/UefiMonitorTest.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 UefiMonitorTest/UefiMonitorTest.h diff --git a/UefiMonitorTest/UefiMonitorTest.c b/UefiMonitorTest/UefiMonitorTest.c index 7cdff88..2d27013 100644 --- a/UefiMonitorTest/UefiMonitorTest.c +++ b/UefiMonitorTest/UefiMonitorTest.c @@ -10,6 +10,39 @@ #include +#include "UefiMonitorTest.h" + +STATIC +VOID +PrepareGraphicsInfo ( + IN GRAPHICS_CONTEXT *Graphics, + IN EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop + ) +{ + ASSERT (Graphics != NULL); + ASSERT (Gop != NULL); + + Graphics->Gop = Gop; + Graphics->Base = (UINT8 *)Gop->Mode->FrameBufferBase; + Graphics->Width = Gop->Mode->Info->HorizontalResolution; + Graphics->Height = Gop->Mode->Info->VerticalResolution; + Graphics->PixelWidth = 4; // A pixel is 32-bits + Graphics->Pitch = Graphics->PixelWidth * Gop->Mode->Info->PixelsPerScanLine; + + DEBUG (( + DEBUG_INFO, + "GOP information:\n" + "Mode: %d\n" + "Support a physical frame buffer: %s\n" + "Framebuffer address, size: %x, %d\n" + "Screen width x height: %d x %d\n", + Gop->Mode->Mode, + (Gop->Mode->Info->PixelFormat == PixelBltOnly) ? L"NO" : L"YES", + Gop->Mode->FrameBufferBase, Gop->Mode->FrameBufferSize, + Gop->Mode->Info->HorizontalResolution, Gop->Mode->Info->VerticalResolution + )); +} + STATIC EFI_GRAPHICS_OUTPUT_PROTOCOL * GetGraphicsOutputProtocol ( @@ -57,6 +90,7 @@ UefiMain ( ) { EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop; + GRAPHICS_CONTEXT Graphics; Gop = GetGraphicsOutputProtocol (); if (Gop == NULL) { @@ -64,5 +98,7 @@ UefiMain ( return EFI_NOT_FOUND; } + PrepareGraphicsInfo (&Graphics, Gop); + return EFI_SUCCESS; } diff --git a/UefiMonitorTest/UefiMonitorTest.h b/UefiMonitorTest/UefiMonitorTest.h new file mode 100644 index 0000000..d6306bc --- /dev/null +++ b/UefiMonitorTest/UefiMonitorTest.h @@ -0,0 +1,32 @@ +#ifndef UEFI_MONITOR_TEST_H +#define UEFI_MONITOR_TEST_H + +typedef struct { + /// + /// The EFI_GRAPHICS_OUTPUT_PROTOCOL instance. + /// + EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop; + /// + /// Base address of graphics linear frame buffer. + /// Starts from the upper left pixel. + /// + UINT8 *Base; + /// + /// The size of video screen in pixels in the X dimension. + /// + UINT32 Width; + /// + /// The size of video screen in pixels in the Y dimension. + /// + UINT32 Height; + /// + /// The size of pixel color in bytes. + /// + UINT32 PixelWidth; + /// + /// Amount of bytes you should skip to go one pixel down. + /// + UINT32 Pitch; +} GRAPHICS_CONTEXT; + +#endif /* UEFI_MONITOR_TEST_H */ -- cgit v1.2.3-18-g5258