Step to UEFI (52) ----- EFI_Graphics_Output_Protocol 清屏幕

EFI_Graphics_Output_Protocol 中的 Blt 可以实现在屏幕上绘制图形的功能。

bvf

其中的一个参数 EfiBltVideoFill 可以用来填充整个屏幕的颜色,从而实现清屏的目的。

#include  <Uefi.h>
#include  <Library/UefiLib.h>
#include  <Library/ShellCEntryLib.h>

#include  <stdio.h>
#include  <stdlib.h>
#include  <wchar.h>
#include  <time.h>
#include <Protocol/EfiShell.h>
#include <Library/ShellLib.h>

#include <Protocol/SimpleFileSystem.h>
#include <Protocol/BlockIo.h>
#include <Library/DevicePathLib.h>
#include <Library/HandleParsingLib.h>
#include <Library/SortLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h>

#include <Protocol/LoadedImage.h>



extern EFI_BOOT_SERVICES         *gBS;
extern EFI_SYSTEM_TABLE			 *gST;
extern EFI_RUNTIME_SERVICES 	 *gRT;

extern EFI_SHELL_ENVIRONMENT2    *mEfiShellEnvironment2;
extern EFI_HANDLE				 gImageHandle;

static EFI_GUID GraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
static EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput = NULL;

//Copied from  C\MdePkg\Include\Protocol\UgaDraw.h
typedef struct {
  UINT8 Blue;
  UINT8 Green;
  UINT8 Red;
  UINT8 Reserved;
} EFI_UGA_PIXEL;

//
// Drawing to the screen
//
VOID egClearScreen(IN EFI_UGA_PIXEL *FillColor)
{
    
    if (GraphicsOutput != NULL) {
        // EFI_GRAPHICS_OUTPUT_BLT_PIXEL and EFI_UGA_PIXEL have the same
        // layout, and the header from TianoCore actually defines them
        // to be the same type.
       GraphicsOutput->Blt(GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)FillColor, EfiBltVideoFill,
                           0, 0, 0, 0, GraphicsOutput->Mode->Info->HorizontalResolution, 
						   GraphicsOutput->Mode->Info->VerticalResolution, 0);
    }
}

int
EFIAPI
main (                                         
  IN int Argc,
  IN char **Argv
  )
{
    EFI_STATUS    Status;
    EFI_UGA_PIXEL color;
	UINTN i;
	
    Status = gBS->LocateProtocol(&GraphicsOutputProtocolGuid, NULL, (VOID **) &GraphicsOutput);
    if (EFI_ERROR(Status)) {
        GraphicsOutput = NULL;
		Print(L"Loading Graphics_Output_Protocol error!\n");
		return EFI_SUCCESS;
	}	

	for (i=0;i<255;i++)
	  {
		color.Blue  = i & 0xFF;	
		color.Green = i & 0xFF;
		color.Red   = i & 0xFF;
	
		egClearScreen(&color);
		gBS->Stall(5000);
	  }
  return EFI_SUCCESS;
  
}

 

工作视频:

http://www.tudou.com/programs/view/W6lvKHdeMX8/?resourceId=414535982_06_02_99

完整代码下载

GFXTest2

参考:

1. 本文参考 https://github.com/chengs 的代码 在此表示感谢!

《Step to UEFI (52) ----- EFI_Graphics_Output_Protocol 清屏幕》有2个想法

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注