The change includes: 1. Rename the following two APIs. The parameters are also refined to add Configure so that this library put all the GOP information into the Configure buffer. BltLibConfigure --> FrameBufferBltConfigure BltLibGopBlt --> FrameBufferBlt 2. Remove the following 5 unnecessary APIs. The first 4 can be replaced with FrameBufferBlt. The last one returns the resolution but the Library consumer should have such information. BltLibVideoFill BltLibVideoToBltBuffer BltLibBufferToVideo BltLibVideoToVideo BltLibGetSizes
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <[email protected]> Cc: Laszlo Ersek <[email protected]> Cc: Jordan Justen <[email protected]> --- .../Application/BltLibSample/BltLibSample.c | 122 ++-- .../Application/BltLibSample/BltLibSample.inf | 5 +- OptionRomPkg/Include/Library/BltLib.h | 259 ------- OptionRomPkg/Include/Library/FrameBufferBltLib.h | 90 +++ .../Library/FrameBufferBltLib/FrameBufferBltLib.c | 807 ++++++++++----------- .../FrameBufferBltLib/FrameBufferBltLib.inf | 3 +- OptionRomPkg/OptionRomPkg.dec | 4 +- OptionRomPkg/OptionRomPkg.dsc | 3 +- 8 files changed, 555 insertions(+), 738 deletions(-) delete mode 100644 OptionRomPkg/Include/Library/BltLib.h create mode 100644 OptionRomPkg/Include/Library/FrameBufferBltLib.h diff --git a/OptionRomPkg/Application/BltLibSample/BltLibSample.c b/OptionRomPkg/Application/BltLibSample/BltLibSample.c index 09fea62..a9fa825 100644 --- a/OptionRomPkg/Application/BltLibSample/BltLibSample.c +++ b/OptionRomPkg/Application/BltLibSample/BltLibSample.c @@ -1,7 +1,7 @@ /** @file Example program using BltLib - Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2006 - 2016, 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 @@ -13,7 +13,8 @@ **/ #include <Uefi.h> -#include <Library/BltLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/FrameBufferBltLib.h> #include <Library/DebugLib.h> #include <Library/UefiLib.h> #include <Library/UefiApplicationEntryPoint.h> @@ -65,10 +66,11 @@ Rand32 ( return R32; } - VOID TestFills ( - VOID + VOID *Configure, + UINT32 HorizontalResolution, + UINT32 VerticalResolution ) { EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color; @@ -77,49 +79,45 @@ TestFills ( UINTN Y; UINTN W; UINTN H; - UINTN Width; - UINTN Height; - BltLibGetSizes (&Width, &Height); for (Loop = 0; Loop < 10000; Loop++) { - W = Width - (Rand32 () % Width); - H = Height - (Rand32 () % Height); - if (W != Width) { - X = Rand32 () % (Width - W); + W = HorizontalResolution - (Rand32 () % HorizontalResolution); + H = VerticalResolution - (Rand32 () % VerticalResolution); + if (W != HorizontalResolution) { + X = Rand32 () % (HorizontalResolution - W); } else { X = 0; } - if (H != Height) { - Y = Rand32 () % (Height - H); + if (H != VerticalResolution) { + Y = Rand32 () % (VerticalResolution - H); } else { Y = 0; } *(UINT32*) (&Color) = Rand32 () & 0xffffff; - BltLibVideoFill (&Color, X, Y, W, H); + FrameBufferBlt (Configure, &Color, EfiBltVideoFill, 0, 0, X, Y, W, H, 0); } } VOID TestColor1 ( - VOID + VOID *Configure, + UINT32 HorizontalResolution, + UINT32 VerticalResolution ) { EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color; UINTN X; UINTN Y; - UINTN Width; - UINTN Height; - BltLibGetSizes (&Width, &Height); *(UINT32*) (&Color) = 0; - for (Y = 0; Y < Height; Y++) { - for (X = 0; X < Width; X++) { - Color.Red = (UINT8) ((X * 0x100) / Width); - Color.Green = (UINT8) ((Y * 0x100) / Height); - Color.Blue = (UINT8) ((Y * 0x100) / Height); - BltLibVideoFill (&Color, X, Y, 1, 1); + for (Y = 0; Y < VerticalResolution; Y++) { + for (X = 0; X < HorizontalResolution; X++) { + Color.Red = (UINT8) ((X * 0x100) / HorizontalResolution); + Color.Green = (UINT8) ((Y * 0x100) / VerticalResolution); + Color.Blue = (UINT8) ((Y * 0x100) / VerticalResolution); + FrameBufferBlt (Configure, &Color, EfiBltVideoFill, 0, 0, X, Y, 1, 1, 0); } } } @@ -180,43 +178,44 @@ GetTriColor ( VOID TestColor ( - VOID + VOID *Configure, + UINT32 HorizontalResolution, + UINT32 VerticalResolution ) { EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color; UINTN X, Y; UINTN X1, X2, X3; UINTN Y1, Y2; - UINTN LineWidth, TriWidth, ScreenWidth; - UINTN TriHeight, ScreenHeight; + UINTN LineWidth, TriWidth; + UINTN TriHeight; UINT32 ColorDist; - BltLibGetSizes (&ScreenWidth, &ScreenHeight); *(UINT32*) (&Color) = 0; - BltLibVideoFill (&Color, 0, 0, ScreenWidth, ScreenHeight); + FrameBufferBlt (Configure, &Color, EfiBltVideoFill, 0, 0, 0, 0, HorizontalResolution, VerticalResolution, 0); TriWidth = (UINTN) DivU64x32 ( - MultU64x32 (11547005, (UINT32) ScreenHeight), + MultU64x32 (11547005, (UINT32) VerticalResolution), 10000000 ); TriHeight = (UINTN) DivU64x32 ( - MultU64x32 (8660254, (UINT32) ScreenWidth), + MultU64x32 (8660254, (UINT32) HorizontalResolution), 10000000 ); - if (TriWidth > ScreenWidth) { + if (TriWidth > HorizontalResolution) { DEBUG ((EFI_D_INFO, "TriWidth at %d was too big\n", TriWidth)); - TriWidth = ScreenWidth; - } else if (TriHeight > ScreenHeight) { + TriWidth = HorizontalResolution; + } else if (TriHeight > VerticalResolution) { DEBUG ((EFI_D_INFO, "TriHeight at %d was too big\n", TriHeight)); - TriHeight = ScreenHeight; + TriHeight = VerticalResolution; } DEBUG ((EFI_D_INFO, "Triangle Width: %d; Height: %d\n", TriWidth, TriHeight)); - X1 = (ScreenWidth - TriWidth) / 2; + X1 = (HorizontalResolution - TriWidth) / 2; X3 = X1 + TriWidth - 1; X2 = (X1 + X3) / 2; - Y2 = (ScreenHeight - TriHeight) / 2; + Y2 = (VerticalResolution - TriHeight) / 2; Y1 = Y2 + TriHeight - 1; for (Y = Y2; Y <= Y1; Y++) { @@ -235,7 +234,7 @@ TestColor ( ColorDist = Uint32Dist(X3 - X, Y1 - Y); Color.Blue = GetTriColor (ColorDist, TriWidth); - BltLibVideoFill (&Color, X, Y, 1, 1); + FrameBufferBlt (Configure, &Color, EfiBltVideoFill, 0, 0, X, Y, 1, 1, 0); } } @@ -245,6 +244,7 @@ TestColor ( VOID TestMove1 ( + VOID *Configure, UINT32 HorizontalResolution, UINT32 VerticalResolution ) @@ -259,15 +259,15 @@ TestMove1 ( Width = 100; Height = 20; - BltLibVideoFill (&Black, 0, 0, HorizontalResolution, VerticalResolution); + FrameBufferBlt (Configure, &Black, EfiBltVideoFill, 0, 0, 0, 0, HorizontalResolution, VerticalResolution, 0); *(UINT32 *) &Blue = 0; Blue.Blue = 0xff; - BltLibVideoFill (&Blue, 0, 0, Width, Height); + FrameBufferBlt (Configure, &Blue, EfiBltVideoFill, 0, 0, 0, 0, Width, Height, 0); for (X = 1, Y = 1; X < HorizontalResolution && Y < VerticalResolution; X++, Y++) { - BltLibVideoToVideo (X - 1, Y - 1, X, Y, Width, Height); - gBS->Stall (100); + FrameBufferBlt (Configure, NULL, EfiBltVideoToVideo, X - 1, Y - 1, X, Y, Width, Height, 0); + gBS->Stall (1000); } gBS->Stall (1000 * 1000 * 2); } @@ -291,7 +291,10 @@ UefiMain ( ) { EFI_STATUS Status; + RETURN_STATUS ReturnStatus; EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop; + VOID *Configure; + UINTN ConfigureSize; Status = gBS->HandleProtocol ( gST->ConsoleOutHandle, @@ -302,19 +305,36 @@ UefiMain ( return Status; } - Status = BltLibConfigure ( - (VOID*)(UINTN) Gop->Mode->FrameBufferBase, - Gop->Mode->Info - ); - if (EFI_ERROR (Status)) { - return Status; + ConfigureSize = 0; + ReturnStatus = FrameBufferBltConfigure ( + (VOID*)(UINTN) Gop->Mode->FrameBufferBase, + Gop->Mode->Info, + NULL, + &ConfigureSize + ); + if (ReturnStatus == RETURN_BUFFER_TOO_SMALL) { + Configure = AllocatePool (ConfigureSize); + if (Configure == NULL) { + ReturnStatus = RETURN_OUT_OF_RESOURCES; + } else { + ReturnStatus = FrameBufferBltConfigure ( + (VOID*) (UINTN) Gop->Mode->FrameBufferBase, + Gop->Mode->Info, + Configure, + &ConfigureSize + ); + } + } + + if (RETURN_ERROR (ReturnStatus)) { + return EFI_ABORTED; } - TestFills (); + TestFills (Configure, Gop->Mode->Info->HorizontalResolution, Gop->Mode->Info->VerticalResolution); - TestColor (); + TestColor (Configure, Gop->Mode->Info->HorizontalResolution, Gop->Mode->Info->VerticalResolution); - TestMove1 (Gop->Mode->Info->HorizontalResolution, Gop->Mode->Info->VerticalResolution); + TestMove1 (Configure, Gop->Mode->Info->HorizontalResolution, Gop->Mode->Info->VerticalResolution); return EFI_SUCCESS; } diff --git a/OptionRomPkg/Application/BltLibSample/BltLibSample.inf b/OptionRomPkg/Application/BltLibSample/BltLibSample.inf index a1334f8..0a3280f 100644 --- a/OptionRomPkg/Application/BltLibSample/BltLibSample.inf +++ b/OptionRomPkg/Application/BltLibSample/BltLibSample.inf @@ -1,7 +1,7 @@ ## @file # Test the BltLib interface # -# Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2008 - 2016, 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 @@ -29,7 +29,6 @@ [Packages] OptionRomPkg/OptionRomPkg.dec [LibraryClasses] - BltLib + FrameBufferBltLib UefiApplicationEntryPoint UefiLib - diff --git a/OptionRomPkg/Include/Library/BltLib.h b/OptionRomPkg/Include/Library/BltLib.h deleted file mode 100644 index 98d49e5..0000000 --- a/OptionRomPkg/Include/Library/BltLib.h +++ /dev/null @@ -1,259 +0,0 @@ -/** @file - Library for performing video blt operations - - Copyright (c) 2009 - 2011, 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. - -**/ - -#ifndef __BLT_LIB__ -#define __BLT_LIB__ - -#include <Protocol/GraphicsOutput.h> - - -/** - Configure the BltLib for a frame-buffer - - @param[in] FrameBuffer Pointer to the start of the frame buffer - @param[in] FrameBufferInfo Describes the frame buffer characteristics - - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - Blt operation success - -**/ -EFI_STATUS -EFIAPI -BltLibConfigure ( - IN VOID *FrameBuffer, - IN EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *FrameBufferInfo - ); - - -/** - Performs a UEFI Graphics Output Protocol Blt operation. - - @param[in,out] BltBuffer - The data to transfer to screen - @param[in] BltOperation - The operation to perform - @param[in] SourceX - The X coordinate of the source for BltOperation - @param[in] SourceY - The Y coordinate of the source for BltOperation - @param[in] DestinationX - The X coordinate of the destination for BltOperation - @param[in] DestinationY - The Y coordinate of the destination for BltOperation - @param[in] Width - The width of a rectangle in the blt rectangle in pixels - @param[in] Height - The height of a rectangle in the blt rectangle in pixels - @param[in] Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation. - If a Delta of 0 is used, the entire BltBuffer will be operated on. - If a subrectangle of the BltBuffer is used, then Delta represents - the number of bytes in a row of the BltBuffer. - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - Blt operation success - -**/ -EFI_STATUS -EFIAPI -BltLibGopBlt ( - IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL - IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, - IN UINTN SourceX, - IN UINTN SourceY, - IN UINTN DestinationX, - IN UINTN DestinationY, - IN UINTN Width, - IN UINTN Height, - IN UINTN Delta - ); - - -/** - Performs a UEFI Graphics Output Protocol Blt Video Fill. - - @param[in] Color Color to fill the region with - @param[in] DestinationX X location to start fill operation - @param[in] DestinationY Y location to start fill operation - @param[in] Width Width (in pixels) to fill - @param[in] Height Height to fill - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - Blt operation success - -**/ -EFI_STATUS -EFIAPI -BltLibVideoFill ( - IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Color, - IN UINTN DestinationX, - IN UINTN DestinationY, - IN UINTN Width, - IN UINTN Height - ); - - -/** - Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation. - - @param[out] BltBuffer Output buffer for pixel color data - @param[in] SourceX X location within video - @param[in] SourceY Y location within video - @param[in] Width Width (in pixels) - @param[in] Height Height - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - Blt operation success - -**/ -EFI_STATUS -EFIAPI -BltLibVideoToBltBuffer ( - OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, - IN UINTN SourceX, - IN UINTN SourceY, - IN UINTN Width, - IN UINTN Height - ); - - -/** - Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation - with extended parameters. - - @param[out] BltBuffer Output buffer for pixel color data - @param[in] SourceX X location within video - @param[in] SourceY Y location within video - @param[in] DestinationX X location within BltBuffer - @param[in] DestinationY Y location within BltBuffer - @param[in] Width Width (in pixels) - @param[in] Height Height - @param[in] Delta Number of bytes in a row of BltBuffer - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - Blt operation success - -**/ -EFI_STATUS -EFIAPI -BltLibVideoToBltBufferEx ( - OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, - IN UINTN SourceX, - IN UINTN SourceY, - IN UINTN DestinationX, - IN UINTN DestinationY, - IN UINTN Width, - IN UINTN Height, - IN UINTN Delta - ); - - -/** - Performs a UEFI Graphics Output Protocol Blt Buffer to Video operation. - - @param[in] BltBuffer Output buffer for pixel color data - @param[in] DestinationX X location within video - @param[in] DestinationY Y location within video - @param[in] Width Width (in pixels) - @param[in] Height Height - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - Blt operation success - -**/ -EFI_STATUS -EFIAPI -BltLibBufferToVideo ( - IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, - IN UINTN DestinationX, - IN UINTN DestinationY, - IN UINTN Width, - IN UINTN Height - ); - - -/** - Performs a UEFI Graphics Output Protocol Blt Buffer to Video operation - with extended parameters. - - @param[in] BltBuffer Output buffer for pixel color data - @param[in] SourceX X location within BltBuffer - @param[in] SourceY Y location within BltBuffer - @param[in] DestinationX X location within video - @param[in] DestinationY Y location within video - @param[in] Width Width (in pixels) - @param[in] Height Height - @param[in] Delta Number of bytes in a row of BltBuffer - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - Blt operation success - -**/ -EFI_STATUS -EFIAPI -BltLibBufferToVideoEx ( - IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, - IN UINTN SourceX, - IN UINTN SourceY, - IN UINTN DestinationX, - IN UINTN DestinationY, - IN UINTN Width, - IN UINTN Height, - IN UINTN Delta - ); - - -/** - Performs a UEFI Graphics Output Protocol Blt Video to Video operation - - @param[in] SourceX X location within video - @param[in] SourceY Y location within video - @param[in] DestinationX X location within video - @param[in] DestinationY Y location within video - @param[in] Width Width (in pixels) - @param[in] Height Height - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - Blt operation success - -**/ -EFI_STATUS -EFIAPI -BltLibVideoToVideo ( - IN UINTN SourceX, - IN UINTN SourceY, - IN UINTN DestinationX, - IN UINTN DestinationY, - IN UINTN Width, - IN UINTN Height - ); - - -/** - Returns the sizes related to the video device - - @param[out] Width Width (in pixels) - @param[out] Height Height (in pixels) - - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - The sizes were returned - -**/ -EFI_STATUS -EFIAPI -BltLibGetSizes ( - OUT UINTN *Width, OPTIONAL - OUT UINTN *Height OPTIONAL - ); - -#endif - diff --git a/OptionRomPkg/Include/Library/FrameBufferBltLib.h b/OptionRomPkg/Include/Library/FrameBufferBltLib.h new file mode 100644 index 0000000..0c167b4 --- /dev/null +++ b/OptionRomPkg/Include/Library/FrameBufferBltLib.h @@ -0,0 +1,90 @@ +/** @file + Library for performing UEFI GOP Blt operations on a framebuffer + + Copyright (c) 2009 - 2016, 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. + +**/ + +#ifndef __FRAMEBUFFER_BLT_LIB__ +#define __FRAMEBUFFER_BLT_LIB__ + +#include <Protocol/GraphicsOutput.h> + + +/** + Create the configuration for a video frame buffer. + + The configuration is returned in the caller provided buffer. + + @param[in] FrameBuffer Pointer to the start of the frame buffer. + @param[in] FrameBufferInfo Describes the frame buffer characteristics. + @param[in,out] Configure The created configuration information. + @param[in,out] ConfigureSize Size of the configuration information. + + @retval RETURN_SUCCESS The configuration was successful created. + @retval RETURN_BUFFER_TOO_SMALL The Configure is to too small. The required + size is returned in ConfigureSize. + @retval RETURN_UNSUPPORTED The requested mode is not supported by + this implementaion. +**/ +RETURN_STATUS +EFIAPI +FrameBufferBltConfigure ( + IN VOID *FrameBuffer, + IN EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *FrameBufferInfo, + IN OUT VOID *Configure, + IN OUT UINTN *ConfigureSize + ); + +/** + Performs a UEFI Graphics Output Protocol Blt operation. + + @param[in] Configure Pointer to a configuration which was successfully + created by FrameBufferBltConfigure (). + @param[in,out] BltBuffer The data to transfer to screen. + @param[in] BltOperation The operation to perform. + @param[in] SourceX The X coordinate of the source for BltOperation. + @param[in] SourceY The Y coordinate of the source for BltOperation. + @param[in] DestinationX The X coordinate of the destination for + BltOperation. + @param[in] DestinationY The Y coordinate of the destination for + BltOperation. + @param[in] Width The width of a rectangle in the blt rectangle + in pixels. + @param[in] Height The height of a rectangle in the blt rectangle + in pixels. + @param[in] Delta Not used for EfiBltVideoFill and + EfiBltVideoToVideo operation. If a Delta of 0 + is used, the entire BltBuffer will be operated + on. If a subrectangle of the BltBuffer is + used, then Delta represents the number of + bytes in a row of the BltBuffer. + + @retval RETURN_INVALID_PARAMETER Invalid parameter were passed in. + @retval RETURN_SUCCESS The Blt operation was performed successfully. +**/ +RETURN_STATUS +EFIAPI +FrameBufferBlt ( + IN VOID *Configure, + IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL + IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN Delta + ); + +#endif diff --git a/OptionRomPkg/Library/FrameBufferBltLib/FrameBufferBltLib.c b/OptionRomPkg/Library/FrameBufferBltLib/FrameBufferBltLib.c index 49ef568..72536c1 100644 --- a/OptionRomPkg/Library/FrameBufferBltLib/FrameBufferBltLib.c +++ b/OptionRomPkg/Library/FrameBufferBltLib/FrameBufferBltLib.c @@ -1,46 +1,53 @@ /** @file FrameBufferBltLib - Library to perform blt operations on a frame buffer. - Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2007 - 2016, 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. **/ -#include <Uefi.h> +#include <Uefi/UefiBaseType.h> +#include <Protocol/GraphicsOutput.h> + #include <Library/BaseLib.h> #include <Library/BaseMemoryLib.h> +#include <Library/FrameBufferBltLib.h> #include <Library/DebugLib.h> -#include <Library/BltLib.h> -#include <Protocol/GraphicsOutput.h> -#if 0 -#define VDEBUG DEBUG -#else -#define VDEBUG(x) -#endif - -#define MAX_LINE_BUFFER_SIZE (SIZE_4KB * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)) - -UINTN mBltLibColorDepth; -UINTN mBltLibWidthInBytes; -UINTN mBltLibBytesPerPixel; -UINTN mBltLibWidthInPixels; -UINTN mBltLibHeight; -UINT8 mBltLibLineBuffer[MAX_LINE_BUFFER_SIZE]; -UINT8 *mBltLibFrameBuffer; -EFI_GRAPHICS_PIXEL_FORMAT mPixelFormat; -EFI_PIXEL_BITMASK mPixelBitMasks; -INTN mPixelShl[4]; // R-G-B-Rsvd -INTN mPixelShr[4]; // R-G-B-Rsvd +#define MAX_LINE_BUFFER_SIZE \ + (SIZE_4KB * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)) + +EFI_PIXEL_BITMASK mRgbPixelMasks = { + 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 +}; + +EFI_PIXEL_BITMASK mBgrPixelMasks = { + 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 +}; + +typedef struct { + UINTN ColorDepth; + UINTN WidthInBytes; + UINTN BytesPerPixel; + UINTN WidthInPixels; + UINTN Height; + UINT8 LineBuffer[MAX_LINE_BUFFER_SIZE]; + UINT8 *FrameBuffer; + EFI_GRAPHICS_PIXEL_FORMAT PixelFormat; + EFI_PIXEL_BITMASK PixelMasks; + INTN PixelShl[4]; // R-G-B-Rsvd + INTN PixelShr[4]; // R-G-B-Rsvd +} FRAMEBUFFER_CONFIGURE; VOID ConfigurePixelBitMaskFormat ( + IN FRAMEBUFFER_CONFIGURE *Configure, IN EFI_PIXEL_BITMASK *BitMask ) { @@ -53,234 +60,181 @@ ConfigurePixelBitMaskFormat ( for (Loop = 0; Loop < 3; Loop++) { ASSERT ((Loop == 3) || (Masks[Loop] != 0)); ASSERT ((MergedMasks & Masks[Loop]) == 0); - mPixelShl[Loop] = HighBitSet32 (Masks[Loop]) - 23 + (Loop * 8); - if (mPixelShl[Loop] < 0) { - mPixelShr[Loop] = -mPixelShl[Loop]; - mPixelShl[Loop] = 0; + Configure->PixelShl[Loop] = HighBitSet32 (Masks[Loop]) - 23 + (Loop * 8); + if (Configure->PixelShl[Loop] < 0) { + Configure->PixelShr[Loop] = -Configure->PixelShl[Loop]; + Configure->PixelShl[Loop] = 0; } else { - mPixelShr[Loop] = 0; + Configure->PixelShr[Loop] = 0; } MergedMasks = (UINT32) (MergedMasks | Masks[Loop]); - DEBUG ((EFI_D_INFO, "%d: shl:%d shr:%d mask:%x\n", Loop, mPixelShl[Loop], mPixelShr[Loop], Masks[Loop])); + DEBUG ((EFI_D_VERBOSE, "%d: shl:%d shr:%d mask:%x\n", Loop, + Configure->PixelShl[Loop], Configure->PixelShr[Loop], Masks[Loop])); } MergedMasks = (UINT32) (MergedMasks | Masks[3]); ASSERT (MergedMasks != 0); - mBltLibBytesPerPixel = (UINTN) ((HighBitSet32 (MergedMasks) + 7) / 8); + Configure->BytesPerPixel = (UINTN) ((HighBitSet32 (MergedMasks) + 7) / 8); - DEBUG ((EFI_D_INFO, "Bytes per pixel: %d\n", mBltLibBytesPerPixel)); + DEBUG ((EFI_D_VERBOSE, "Bytes per pixel: %d\n", Configure->BytesPerPixel)); - CopyMem (&mPixelBitMasks, BitMask, sizeof (*BitMask)); + CopyMem (&Configure->PixelMasks, BitMask, sizeof (*BitMask)); } /** - Configure the FrameBufferLib instance + Create the configuration for a video frame buffer. + + The configuration is returned in the caller provided buffer. - @param[in] FrameBuffer Pointer to the start of the frame buffer - @param[in] FrameBufferInfo Describes the frame buffer characteristics + @param[in] FrameBuffer Pointer to the start of the frame buffer. + @param[in] FrameBufferInfo Describes the frame buffer characteristics. + @param[in,out] Configure The created configuration information. + @param[in,out] ConfigureSize Size of the configuration information. - @retval EFI_INVALID_PARAMETER - Invalid parameter - @retval EFI_UNSUPPORTED - The BltLib does not support this configuration - @retval EFI_SUCCESS - Blt operation success + @retval RETURN_SUCCESS The configuration was successful created. + @retval RETURN_BUFFER_TOO_SMALL The Configure is to too small. The required + size is returned in ConfigureSize. + @retval RETURN_UNSUPPORTED The requested mode is not supported by + this implementaion. **/ -EFI_STATUS +RETURN_STATUS EFIAPI -BltLibConfigure ( - IN VOID *FrameBuffer, - IN EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *FrameBufferInfo +FrameBufferBltConfigure ( + IN VOID *FrameBuffer, + IN EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *FrameBufferInfo, + IN OUT VOID *Configure, + IN OUT UINTN *ConfigureSize ) { - STATIC EFI_PIXEL_BITMASK RgbPixelMasks = - { 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }; - STATIC EFI_PIXEL_BITMASK BgrPixelMasks = - { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }; + FRAMEBUFFER_CONFIGURE *Cb; + + if (ConfigureSize == NULL) { + return RETURN_INVALID_PARAMETER; + } + + if (*ConfigureSize < sizeof (FRAMEBUFFER_CONFIGURE)) { + *ConfigureSize = sizeof (FRAMEBUFFER_CONFIGURE); + return RETURN_BUFFER_TOO_SMALL; + } + + if (Configure == NULL) { + return RETURN_INVALID_PARAMETER; + } + + Cb = Configure; switch (FrameBufferInfo->PixelFormat) { case PixelRedGreenBlueReserved8BitPerColor: - ConfigurePixelBitMaskFormat (&RgbPixelMasks); + ConfigurePixelBitMaskFormat (Cb, &mRgbPixelMasks); break; + case PixelBlueGreenRedReserved8BitPerColor: - ConfigurePixelBitMaskFormat (&BgrPixelMasks); + ConfigurePixelBitMaskFormat (Cb, &mBgrPixelMasks); break; + case PixelBitMask: - ConfigurePixelBitMaskFormat (&(FrameBufferInfo->PixelInformation)); + ConfigurePixelBitMaskFormat (Cb, &(FrameBufferInfo->PixelInformation)); break; + case PixelBltOnly: ASSERT (FrameBufferInfo->PixelFormat != PixelBltOnly); - return EFI_UNSUPPORTED; + return RETURN_UNSUPPORTED; + default: ASSERT (FALSE); - return EFI_INVALID_PARAMETER; + return RETURN_INVALID_PARAMETER; } - mPixelFormat = FrameBufferInfo->PixelFormat; - - mBltLibFrameBuffer = (UINT8*) FrameBuffer; - mBltLibWidthInPixels = (UINTN) FrameBufferInfo->HorizontalResolution; - mBltLibHeight = (UINTN) FrameBufferInfo->VerticalResolution; - mBltLibWidthInBytes = mBltLibWidthInPixels * mBltLibBytesPerPixel; - - ASSERT (mBltLibWidthInBytes < sizeof (mBltLibLineBuffer)); - - return EFI_SUCCESS; -} - -/** - Performs a UEFI Graphics Output Protocol Blt operation. - - @param[in,out] BltBuffer - The data to transfer to screen - @param[in] BltOperation - The operation to perform - @param[in] SourceX - The X coordinate of the source for BltOperation - @param[in] SourceY - The Y coordinate of the source for BltOperation - @param[in] DestinationX - The X coordinate of the destination for BltOperation - @param[in] DestinationY - The Y coordinate of the destination for BltOperation - @param[in] Width - The width of a rectangle in the blt rectangle in pixels - @param[in] Height - The height of a rectangle in the blt rectangle in pixels - @param[in] Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation. - If a Delta of 0 is used, the entire BltBuffer will be operated on. - If a subrectangle of the BltBuffer is used, then Delta represents - the number of bytes in a row of the BltBuffer. - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - Blt operation success - -**/ -EFI_STATUS -EFIAPI -BltLibGopBlt ( - IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL - IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, - IN UINTN SourceX, - IN UINTN SourceY, - IN UINTN DestinationX, - IN UINTN DestinationY, - IN UINTN Width, - IN UINTN Height, - IN UINTN Delta - ) -{ - switch (BltOperation) { - case EfiBltVideoToBltBuffer: - return BltLibVideoToBltBufferEx ( - BltBuffer, - SourceX, - SourceY, - DestinationX, - DestinationY, - Width, - Height, - Delta - ); - case EfiBltVideoToVideo: - return BltLibVideoToVideo ( - SourceX, - SourceY, - DestinationX, - DestinationY, - Width, - Height - ); + Cb->PixelFormat = FrameBufferInfo->PixelFormat; + Cb->FrameBuffer = (UINT8*) FrameBuffer; + Cb->WidthInPixels = (UINTN) FrameBufferInfo->HorizontalResolution; + Cb->Height = (UINTN) FrameBufferInfo->VerticalResolution; + Cb->WidthInBytes = Cb->WidthInPixels * Cb->BytesPerPixel; - case EfiBltVideoFill: - return BltLibVideoFill ( - BltBuffer, - DestinationX, - DestinationY, - Width, - Height - ); + ASSERT (Cb->WidthInBytes < sizeof (Cb->LineBuffer)); - case EfiBltBufferToVideo: - return BltLibBufferToVideoEx ( - BltBuffer, - SourceX, - SourceY, - DestinationX, - DestinationY, - Width, - Height, - Delta - ); - default: - return EFI_INVALID_PARAMETER; - } + return RETURN_SUCCESS; } /** Performs a UEFI Graphics Output Protocol Blt Video Fill. - @param[in] Color Color to fill the region with - @param[in] DestinationX X location to start fill operation - @param[in] DestinationY Y location to start fill operation - @param[in] Width Width (in pixels) to fill - @param[in] Height Height to fill + @param[in] Cb Pointer to a configuration which was successfully + created by FrameBufferBltConfigure (). + @param[in] Color Color to fill the region with. + @param[in] DestinationX X location to start fill operation. + @param[in] DestinationY Y location to start fill operation. + @param[in] Width Width (in pixels) to fill. + @param[in] Height Height to fill. - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - The sizes were returned + @retval RETURN_INVALID_PARAMETER Invalid parameter was passed in. + @retval RETURN_SUCCESS The video was filled successfully. **/ EFI_STATUS -EFIAPI -BltLibVideoFill ( - IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Color, - IN UINTN DestinationX, - IN UINTN DestinationY, - IN UINTN Width, - IN UINTN Height +FrameBufferBltLibVideoFill ( + IN FRAMEBUFFER_CONFIGURE *Cb, + IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Color, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height ) { - UINTN Y; - UINT8 *Destination; - UINTN X; - UINT8 Uint8; - UINT32 Uint32; - UINT64 WideFill; - BOOLEAN UseWideFill; - BOOLEAN LineBufferReady; - UINTN Offset; - UINTN WidthInBytes; - UINTN SizeInBytes; + UINTN X; + UINTN Y; + UINT8 *Destination; + UINT8 Uint8; + UINT32 Uint32; + UINT64 WideFill; + BOOLEAN UseWideFill; + BOOLEAN LineBufferReady; + UINTN Offset; + UINTN WidthInBytes; + UINTN SizeInBytes; // // BltBuffer to Video: Source is BltBuffer, destination is Video // - if (DestinationY + Height > mBltLibHeight) { - DEBUG ((EFI_D_INFO, "VideoFill: Past screen (Y)\n")); - return EFI_INVALID_PARAMETER; + if (DestinationY + Height > Cb->Height) { + DEBUG ((EFI_D_VERBOSE, "VideoFill: Past screen (Y)\n")); + return RETURN_INVALID_PARAMETER; } - if (DestinationX + Width > mBltLibWidthInPixels) { - DEBUG ((EFI_D_INFO, "VideoFill: Past screen (X)\n")); - return EFI_INVALID_PARAMETER; + if (DestinationX + Width > Cb->WidthInPixels) { + DEBUG ((EFI_D_VERBOSE, "VideoFill: Past screen (X)\n")); + return RETURN_INVALID_PARAMETER; } if (Width == 0 || Height == 0) { - DEBUG ((EFI_D_INFO, "VideoFill: Width or Height is 0\n")); - return EFI_INVALID_PARAMETER; + DEBUG ((EFI_D_VERBOSE, "VideoFill: Width or Height is 0\n")); + return RETURN_INVALID_PARAMETER; } - WidthInBytes = Width * mBltLibBytesPerPixel; + WidthInBytes = Width * Cb->BytesPerPixel; Uint32 = *(UINT32*) Color; WideFill = (UINT32) ( - (((Uint32 << mPixelShl[0]) >> mPixelShr[0]) & mPixelBitMasks.RedMask) | - (((Uint32 << mPixelShl[1]) >> mPixelShr[1]) & mPixelBitMasks.GreenMask) | - (((Uint32 << mPixelShl[2]) >> mPixelShr[2]) & mPixelBitMasks.BlueMask) + (((Uint32 << Cb->PixelShl[0]) >> Cb->PixelShr[0]) & + Cb->PixelMasks.RedMask) | + (((Uint32 << Cb->PixelShl[1]) >> Cb->PixelShr[1]) & + Cb->PixelMasks.GreenMask) | + (((Uint32 << Cb->PixelShl[2]) >> Cb->PixelShr[2]) & + Cb->PixelMasks.BlueMask) ); - VDEBUG ((EFI_D_INFO, "VideoFill: color=0x%x, wide-fill=0x%x\n", Uint32, WideFill)); + DEBUG ((EFI_D_VERBOSE, "VideoFill: color=0x%x, wide-fill=0x%x\n", + Uint32, WideFill)); // // If the size of the pixel data evenly divides the sizeof // WideFill, then a wide fill operation can be used // UseWideFill = TRUE; - if ((sizeof (WideFill) % mBltLibBytesPerPixel) == 0) { - for (X = mBltLibBytesPerPixel; X < sizeof (WideFill); X++) { - ((UINT8*)&WideFill)[X] = ((UINT8*)&WideFill)[X % mBltLibBytesPerPixel]; + if ((sizeof (WideFill) % Cb->BytesPerPixel) == 0) { + for (X = Cb->BytesPerPixel; X < sizeof (WideFill); X++) { + ((UINT8*) &WideFill)[X] = ((UINT8*) &WideFill)[X % Cb->BytesPerPixel]; } } else { // @@ -288,10 +242,10 @@ BltLibVideoFill ( // a wide fill operation. // for ( - X = 1, Uint8 = ((UINT8*)&WideFill)[0]; - X < mBltLibBytesPerPixel; + X = 1, Uint8 = ((UINT8*) &WideFill)[0]; + X < Cb->BytesPerPixel; X++) { - if (Uint8 != ((UINT8*)&WideFill)[X]) { + if (Uint8 != ((UINT8*) &WideFill)[X]) { UseWideFill = FALSE; break; } @@ -301,28 +255,28 @@ BltLibVideoFill ( } } - if (UseWideFill && (DestinationX == 0) && (Width == mBltLibWidthInPixels)) { - VDEBUG ((EFI_D_INFO, "VideoFill (wide, one-shot)\n")); - Offset = DestinationY * mBltLibWidthInPixels; - Offset = mBltLibBytesPerPixel * Offset; - Destination = mBltLibFrameBuffer + Offset; + if (UseWideFill && (DestinationX == 0) && (Width == Cb->WidthInPixels)) { + DEBUG ((EFI_D_VERBOSE, "VideoFill (wide, one-shot)\n")); + Offset = DestinationY * Cb->WidthInPixels; + Offset = Cb->BytesPerPixel * Offset; + Destination = Cb->FrameBuffer + Offset; SizeInBytes = WidthInBytes * Height; if (SizeInBytes >= 8) { SetMem32 (Destination, SizeInBytes & ~3, (UINT32) WideFill); SizeInBytes &= 3; } if (SizeInBytes > 0) { - SetMem (Destination, SizeInBytes, (UINT8)(UINTN) WideFill); + SetMem (Destination, SizeInBytes, (UINT8) (UINTN) WideFill); } } else { LineBufferReady = FALSE; for (Y = DestinationY; Y < (Height + DestinationY); Y++) { - Offset = (Y * mBltLibWidthInPixels) + DestinationX; - Offset = mBltLibBytesPerPixel * Offset; - Destination = mBltLibFrameBuffer + Offset; + Offset = (Y * Cb->WidthInPixels) + DestinationX; + Offset = Cb->BytesPerPixel * Offset; + Destination = Cb->FrameBuffer + Offset; if (UseWideFill && (((UINTN) Destination & 7) == 0)) { - VDEBUG ((EFI_D_INFO, "VideoFill (wide)\n")); + DEBUG ((EFI_D_VERBOSE, "VideoFill (wide)\n")); SizeInBytes = WidthInBytes; if (SizeInBytes >= 8) { SetMem64 (Destination, SizeInBytes & ~7, WideFill); @@ -332,222 +286,156 @@ BltLibVideoFill ( CopyMem (Destination, &WideFill, SizeInBytes); } } else { - VDEBUG ((EFI_D_INFO, "VideoFill (not wide)\n")); + DEBUG ((EFI_D_VERBOSE, "VideoFill (not wide)\n")); if (!LineBufferReady) { - CopyMem (mBltLibLineBuffer, &WideFill, mBltLibBytesPerPixel); + CopyMem (Cb->LineBuffer, &WideFill, Cb->BytesPerPixel); for (X = 1; X < Width; ) { - CopyMem( - (mBltLibLineBuffer + (X * mBltLibBytesPerPixel)), - mBltLibLineBuffer, - MIN (X, Width - X) * mBltLibBytesPerPixel - ); + CopyMem ( + (Cb->LineBuffer + (X * Cb->BytesPerPixel)), + Cb->LineBuffer, + MIN (X, Width - X) * Cb->BytesPerPixel + ); X += MIN (X, Width - X); } LineBufferReady = TRUE; } - CopyMem (Destination, mBltLibLineBuffer, WidthInBytes); + CopyMem (Destination, Cb->LineBuffer, WidthInBytes); } } } - return EFI_SUCCESS; -} - -/** - Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation. - - @param[out] BltBuffer Output buffer for pixel color data - @param[in] SourceX X location within video - @param[in] SourceY Y location within video - @param[in] Width Width (in pixels) - @param[in] Height Height - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - The sizes were returned - -**/ -EFI_STATUS -EFIAPI -BltLibVideoToBltBuffer ( - OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, - IN UINTN SourceX, - IN UINTN SourceY, - IN UINTN Width, - IN UINTN Height - ) -{ - return BltLibVideoToBltBufferEx ( - BltBuffer, - SourceX, - SourceY, - 0, - 0, - Width, - Height, - 0 - ); + return RETURN_SUCCESS; } /** Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation with extended parameters. - @param[out] BltBuffer Output buffer for pixel color data - @param[in] SourceX X location within video - @param[in] SourceY Y location within video - @param[in] DestinationX X location within BltBuffer - @param[in] DestinationY Y location within BltBuffer - @param[in] Width Width (in pixels) - @param[in] Height Height - @param[in] Delta Number of bytes in a row of BltBuffer - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - The sizes were returned - + @param[in] Cb Pointer to a configuration which was successfully + created by FrameBufferBltConfigure (). + @param[out] BltBuffer Output buffer for pixel color data. + @param[in] SourceX X location within video. + @param[in] SourceY Y location within video. + @param[in] DestinationX X location within BltBuffer. + @param[in] DestinationY Y location within BltBuffer. + @param[in] Width Width (in pixels). + @param[in] Height Height. + @param[in] Delta Number of bytes in a row of BltBuffer. + + @retval RETURN_INVALID_PARAMETER Invalid parameter were passed in. + @retval RETURN_SUCCESS The Blt operation was performed successfully. **/ -EFI_STATUS -EFIAPI -BltLibVideoToBltBufferEx ( - OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, - IN UINTN SourceX, - IN UINTN SourceY, - IN UINTN DestinationX, - IN UINTN DestinationY, - IN UINTN Width, - IN UINTN Height, - IN UINTN Delta +RETURN_STATUS +FrameBufferBltLibVideoToBltBuffer ( + IN FRAMEBUFFER_CONFIGURE *Cb, + OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN Delta ) { - UINTN DstY; - UINTN SrcY; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; - UINT8 *Source; - UINT8 *Destination; - UINTN X; - UINT32 Uint32; - UINTN Offset; - UINTN WidthInBytes; + UINTN DstY; + UINTN SrcY; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; + UINT8 *Source; + UINT8 *Destination; + UINTN X; + UINT32 Uint32; + UINTN Offset; + UINTN WidthInBytes; // // Video to BltBuffer: Source is Video, destination is BltBuffer // - if (SourceY + Height > mBltLibHeight) { - return EFI_INVALID_PARAMETER; + if (SourceY + Height > Cb->Height) { + return RETURN_INVALID_PARAMETER; } - if (SourceX + Width > mBltLibWidthInPixels) { - return EFI_INVALID_PARAMETER; + if (SourceX + Width > Cb->WidthInPixels) { + return RETURN_INVALID_PARAMETER; } if (Width == 0 || Height == 0) { - return EFI_INVALID_PARAMETER; + return RETURN_INVALID_PARAMETER; } // - // If Delta is zero, then the entire BltBuffer is being used, so Delta - // is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size, - // the number of bytes in each row can be computed. + // If Delta is zero, then the entire BltBuffer is being used, so Delta is + // the number of bytes in each row of BltBuffer. Since BltBuffer is Width + // pixels size, the number of bytes in each row can be computed. // if (Delta == 0) { Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL); } - WidthInBytes = Width * mBltLibBytesPerPixel; + WidthInBytes = Width * Cb->BytesPerPixel; // // Video to BltBuffer: Source is Video, destination is BltBuffer // - for (SrcY = SourceY, DstY = DestinationY; DstY < (Height + DestinationY); SrcY++, DstY++) { + for (SrcY = SourceY, DstY = DestinationY; + DstY < (Height + DestinationY); + SrcY++, DstY++) { - Offset = (SrcY * mBltLibWidthInPixels) + SourceX; - Offset = mBltLibBytesPerPixel * Offset; - Source = mBltLibFrameBuffer + Offset; + Offset = (SrcY * Cb->WidthInPixels) + SourceX; + Offset = Cb->BytesPerPixel * Offset; + Source = Cb->FrameBuffer + Offset; - if (mPixelFormat == PixelBlueGreenRedReserved8BitPerColor) { + if (Cb->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) { Destination = (UINT8 *) BltBuffer + (DstY * Delta) + (DestinationX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); } else { - Destination = mBltLibLineBuffer; + Destination = Cb->LineBuffer; } CopyMem (Destination, Source, WidthInBytes); - if (mPixelFormat != PixelBlueGreenRedReserved8BitPerColor) { + if (Cb->PixelFormat != PixelBlueGreenRedReserved8BitPerColor) { for (X = 0; X < Width; X++) { - Blt = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) ((UINT8 *) BltBuffer + (DstY * Delta) + (DestinationX + X) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); - Uint32 = *(UINT32*) (mBltLibLineBuffer + (X * mBltLibBytesPerPixel)); + Blt = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) + ((UINT8 *) BltBuffer + (DstY * Delta) + + (DestinationX + X) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); + Uint32 = *(UINT32*) (Cb->LineBuffer + (X * Cb->BytesPerPixel)); *(UINT32*) Blt = (UINT32) ( - (((Uint32 & mPixelBitMasks.RedMask) >> mPixelShl[0]) << mPixelShr[0]) | - (((Uint32 & mPixelBitMasks.GreenMask) >> mPixelShl[1]) << mPixelShr[1]) | - (((Uint32 & mPixelBitMasks.BlueMask) >> mPixelShl[2]) << mPixelShr[2]) + (((Uint32 & Cb->PixelMasks.RedMask) >> + Cb->PixelShl[0]) << Cb->PixelShr[0]) | + (((Uint32 & Cb->PixelMasks.GreenMask) >> + Cb->PixelShl[1]) << Cb->PixelShr[1]) | + (((Uint32 & Cb->PixelMasks.BlueMask) >> + Cb->PixelShl[2]) << Cb->PixelShr[2]) ); } } } - return EFI_SUCCESS; + return RETURN_SUCCESS; } /** - Performs a UEFI Graphics Output Protocol Blt Buffer to Video operation. - - @param[in] BltBuffer Output buffer for pixel color data - @param[in] DestinationX X location within video - @param[in] DestinationY Y location within video - @param[in] Width Width (in pixels) - @param[in] Height Height - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - The sizes were returned - -**/ -EFI_STATUS -EFIAPI -BltLibBufferToVideo ( - IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, - IN UINTN DestinationX, - IN UINTN DestinationY, - IN UINTN Width, - IN UINTN Height - ) -{ - return BltLibBufferToVideoEx ( - BltBuffer, - 0, - 0, - DestinationX, - DestinationY, - Width, - Height, - 0 - ); -} - - -/** Performs a UEFI Graphics Output Protocol Blt Buffer to Video operation with extended parameters. - @param[in] BltBuffer Output buffer for pixel color data - @param[in] SourceX X location within BltBuffer - @param[in] SourceY Y location within BltBuffer - @param[in] DestinationX X location within video - @param[in] DestinationY Y location within video - @param[in] Width Width (in pixels) - @param[in] Height Height - @param[in] Delta Number of bytes in a row of BltBuffer - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - The sizes were returned - + @param[in] Cb Pointer to a configuration which was successfully + created by FrameBufferBltConfigure (). + @param[in] BltBuffer Output buffer for pixel color data. + @param[in] SourceX X location within BltBuffer. + @param[in] SourceY Y location within BltBuffer. + @param[in] DestinationX X location within video. + @param[in] DestinationY Y location within video. + @param[in] Width Width (in pixels). + @param[in] Height Height. + @param[in] Delta Number of bytes in a row of BltBuffer. + + @retval RETURN_INVALID_PARAMETER Invalid parameter were passed in. + @retval RETURN_SUCCESS The Blt operation was performed successfully. **/ -EFI_STATUS -EFIAPI -BltLibBufferToVideoEx ( +RETURN_STATUS +FrameBufferBltLibBufferToVideo ( + IN FRAMEBUFFER_CONFIGURE *Cb, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, IN UINTN SourceX, IN UINTN SourceY, @@ -571,36 +459,38 @@ BltLibBufferToVideoEx ( // // BltBuffer to Video: Source is BltBuffer, destination is Video // - if (DestinationY + Height > mBltLibHeight) { - return EFI_INVALID_PARAMETER; + if (DestinationY + Height > Cb->Height) { + return RETURN_INVALID_PARAMETER; } - if (DestinationX + Width > mBltLibWidthInPixels) { - return EFI_INVALID_PARAMETER; + if (DestinationX + Width > Cb->WidthInPixels) { + return RETURN_INVALID_PARAMETER; } if (Width == 0 || Height == 0) { - return EFI_INVALID_PARAMETER; + return RETURN_INVALID_PARAMETER; } // - // If Delta is zero, then the entire BltBuffer is being used, so Delta - // is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size, - // the number of bytes in each row can be computed. + // If Delta is zero, then the entire BltBuffer is being used, so Delta is + // the number of bytes in each row of BltBuffer. Since BltBuffer is Width + // pixels size, the number of bytes in each row can be computed. // if (Delta == 0) { Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL); } - WidthInBytes = Width * mBltLibBytesPerPixel; + WidthInBytes = Width * Cb->BytesPerPixel; - for (SrcY = SourceY, DstY = DestinationY; SrcY < (Height + SourceY); SrcY++, DstY++) { + for (SrcY = SourceY, DstY = DestinationY; + SrcY < (Height + SourceY); + SrcY++, DstY++) { - Offset = (DstY * mBltLibWidthInPixels) + DestinationX; - Offset = mBltLibBytesPerPixel * Offset; - Destination = mBltLibFrameBuffer + Offset; + Offset = (DstY * Cb->WidthInPixels) + DestinationX; + Offset = Cb->BytesPerPixel * Offset; + Destination = Cb->FrameBuffer + Offset; - if (mPixelFormat == PixelBlueGreenRedReserved8BitPerColor) { + if (Cb->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) { Source = (UINT8 *) BltBuffer + (SrcY * Delta); } else { for (X = 0; X < Width; X++) { @@ -611,40 +501,43 @@ BltLibBufferToVideoEx ( ((SourceX + X) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)) ); Uint32 = *(UINT32*) Blt; - *(UINT32*) (mBltLibLineBuffer + (X * mBltLibBytesPerPixel)) = + *(UINT32*) (Cb->LineBuffer + (X * Cb->BytesPerPixel)) = (UINT32) ( - (((Uint32 << mPixelShl[0]) >> mPixelShr[0]) & mPixelBitMasks.RedMask) | - (((Uint32 << mPixelShl[1]) >> mPixelShr[1]) & mPixelBitMasks.GreenMask) | - (((Uint32 << mPixelShl[2]) >> mPixelShr[2]) & mPixelBitMasks.BlueMask) + (((Uint32 << Cb->PixelShl[0]) >> Cb->PixelShr[0]) & + Cb->PixelMasks.RedMask) | + (((Uint32 << Cb->PixelShl[1]) >> Cb->PixelShr[1]) & + Cb->PixelMasks.GreenMask) | + (((Uint32 << Cb->PixelShl[2]) >> Cb->PixelShr[2]) & + Cb->PixelMasks.BlueMask) ); } - Source = mBltLibLineBuffer; + Source = Cb->LineBuffer; } CopyMem (Destination, Source, WidthInBytes); } - return EFI_SUCCESS; + return RETURN_SUCCESS; } /** Performs a UEFI Graphics Output Protocol Blt Video to Video operation - @param[in] SourceX X location within video - @param[in] SourceY Y location within video - @param[in] DestinationX X location within video - @param[in] DestinationY Y location within video - @param[in] Width Width (in pixels) - @param[in] Height Height - - @retval EFI_DEVICE_ERROR - A hardware error occured - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - The sizes were returned - + @param[in] Cb Pointer to a configuration which was successfully + created by FrameBufferBltConfigure (). + @param[in] SourceX X location within video. + @param[in] SourceY Y location within video. + @param[in] DestinationX X location within video. + @param[in] DestinationY Y location within video. + @param[in] Width Width (in pixels). + @param[in] Height Height. + + @retval RETURN_INVALID_PARAMETER Invalid parameter were passed in. + @retval RETURN_SUCCESS The Blt operation was performed successfully. **/ -EFI_STATUS -EFIAPI -BltLibVideoToVideo ( +RETURN_STATUS +FrameBufferBltLibVideoToVideo ( + IN FRAMEBUFFER_CONFIGURE *Cb, IN UINTN SourceX, IN UINTN SourceY, IN UINTN DestinationX, @@ -662,37 +555,37 @@ BltLibVideoToVideo ( // // Video to Video: Source is Video, destination is Video // - if (SourceY + Height > mBltLibHeight) { - return EFI_INVALID_PARAMETER; + if (SourceY + Height > Cb->Height) { + return RETURN_INVALID_PARAMETER; } - if (SourceX + Width > mBltLibWidthInPixels) { - return EFI_INVALID_PARAMETER; + if (SourceX + Width > Cb->WidthInPixels) { + return RETURN_INVALID_PARAMETER; } - if (DestinationY + Height > mBltLibHeight) { - return EFI_INVALID_PARAMETER; + if (DestinationY + Height > Cb->Height) { + return RETURN_INVALID_PARAMETER; } - if (DestinationX + Width > mBltLibWidthInPixels) { - return EFI_INVALID_PARAMETER; + if (DestinationX + Width > Cb->WidthInPixels) { + return RETURN_INVALID_PARAMETER; } if (Width == 0 || Height == 0) { - return EFI_INVALID_PARAMETER; + return RETURN_INVALID_PARAMETER; } - WidthInBytes = Width * mBltLibBytesPerPixel; + WidthInBytes = Width * Cb->BytesPerPixel; - Offset = (SourceY * mBltLibWidthInPixels) + SourceX; - Offset = mBltLibBytesPerPixel * Offset; - Source = mBltLibFrameBuffer + Offset; + Offset = (SourceY * Cb->WidthInPixels) + SourceX; + Offset = Cb->BytesPerPixel * Offset; + Source = Cb->FrameBuffer + Offset; - Offset = (DestinationY * mBltLibWidthInPixels) + DestinationX; - Offset = mBltLibBytesPerPixel * Offset; - Destination = mBltLibFrameBuffer + Offset; + Offset = (DestinationY * Cb->WidthInPixels) + DestinationX; + Offset = Cb->BytesPerPixel * Offset; + Destination = Cb->FrameBuffer + Offset; - LineStride = mBltLibWidthInBytes; + LineStride = Cb->WidthInBytes; if (Destination > Source) { // // Copy from last line to avoid source is corrupted by copying @@ -709,32 +602,108 @@ BltLibVideoToVideo ( Destination += LineStride; } - return EFI_SUCCESS; + return RETURN_SUCCESS; } /** - Returns the sizes related to the video device - - @param[out] Width Width (in pixels) - @param[out] Height Height (in pixels) - - @retval EFI_INVALID_PARAMETER - Invalid parameter passed in - @retval EFI_SUCCESS - The sizes were returned + Performs a UEFI Graphics Output Protocol Blt operation. + @param[in] Configure Pointer to a configuration which was successfully + created by FrameBufferBltConfigure (). + @param[in,out] BltBuffer The data to transfer to screen. + @param[in] BltOperation The operation to perform. + @param[in] SourceX The X coordinate of the source for BltOperation. + @param[in] SourceY The Y coordinate of the source for BltOperation. + @param[in] DestinationX The X coordinate of the destination for + BltOperation. + @param[in] DestinationY The Y coordinate of the destination for + BltOperation. + @param[in] Width The width of a rectangle in the blt rectangle + in pixels. + @param[in] Height The height of a rectangle in the blt rectangle + in pixels. + @param[in] Delta Not used for EfiBltVideoFill and + EfiBltVideoToVideo operation. If a Delta of 0 + is used, the entire BltBuffer will be operated + on. If a subrectangle of the BltBuffer is + used, then Delta represents the number of + bytes in a row of the BltBuffer. + + @retval RETURN_INVALID_PARAMETER Invalid parameter were passed in. + @retval RETURN_SUCCESS The Blt operation was performed successfully. **/ -EFI_STATUS +RETURN_STATUS EFIAPI -BltLibGetSizes ( - OUT UINTN *Width, OPTIONAL - OUT UINTN *Height OPTIONAL +FrameBufferBlt ( + IN VOID *Configure, + IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL + IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN Delta ) { - if (Width != NULL) { - *Width = mBltLibWidthInPixels; - } - if (Height != NULL) { - *Height = mBltLibHeight; + FRAMEBUFFER_CONFIGURE *Cb; + + if (Configure == NULL) { + return RETURN_INVALID_PARAMETER; } - return EFI_SUCCESS; + Cb = Configure; + + switch (BltOperation) { + case EfiBltVideoToBltBuffer: + return FrameBufferBltLibVideoToBltBuffer ( + Cb, + BltBuffer, + SourceX, + SourceY, + DestinationX, + DestinationY, + Width, + Height, + Delta + ); + + case EfiBltVideoToVideo: + return FrameBufferBltLibVideoToVideo ( + Cb, + SourceX, + SourceY, + DestinationX, + DestinationY, + Width, + Height + ); + + case EfiBltVideoFill: + return FrameBufferBltLibVideoFill ( + Cb, + BltBuffer, + DestinationX, + DestinationY, + Width, + Height + ); + + case EfiBltBufferToVideo: + return FrameBufferBltLibBufferToVideo ( + Cb, + BltBuffer, + SourceX, + SourceY, + DestinationX, + DestinationY, + Width, + Height, + Delta + ); + + default: + return RETURN_INVALID_PARAMETER; + } } diff --git a/OptionRomPkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf b/OptionRomPkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf index b94b52a..d2861df 100644 --- a/OptionRomPkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf +++ b/OptionRomPkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf @@ -1,7 +1,7 @@ ## @file # FrameBufferBltLib - Library to perform blt operations on a frame buffer. # -# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2006 - 2016, 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 @@ -32,4 +32,3 @@ [LibraryClasses] [Packages] MdePkg/MdePkg.dec OptionRomPkg/OptionRomPkg.dec - diff --git a/OptionRomPkg/OptionRomPkg.dec b/OptionRomPkg/OptionRomPkg.dec index ea4d57b..09d208e 100644 --- a/OptionRomPkg/OptionRomPkg.dec +++ b/OptionRomPkg/OptionRomPkg.dec @@ -6,7 +6,7 @@ # Option ROM image for all CPU architectures, including EBC target. # A single driver can support mixes of EFI 1.1, UEFI 2.0 and UEFI 2.1. # -# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2007 - 2016, 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 @@ -31,7 +31,7 @@ [LibraryClasses] ## @libraryclass Provides an interface for performing UEFI Graphics ## Output Protocol Video blt operations ## - BltLib|Include/Library/BltLib.h + FrameBufferBltLib|Include/Library/FrameBufferBltLib.h [Guids] gOptionRomPkgTokenSpaceGuid = { 0x1e43298f, 0x3478, 0x41a7, { 0xb5, 0x77, 0x86, 0x6, 0x46, 0x35, 0xc7, 0x28 } } diff --git a/OptionRomPkg/OptionRomPkg.dsc b/OptionRomPkg/OptionRomPkg.dsc index 03592f8..97b21b3 100644 --- a/OptionRomPkg/OptionRomPkg.dsc +++ b/OptionRomPkg/OptionRomPkg.dsc @@ -47,7 +47,7 @@ [LibraryClasses] DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf - BltLib|OptionRomPkg/Library/GopBltLib/GopBltLib.inf + BltLib|OptionRomPkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf @@ -99,7 +99,6 @@ [PcdsFixedAtBuild] [Components] OptionRomPkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf - OptionRomPkg/Library/GopBltLib/GopBltLib.inf OptionRomPkg/AtapiPassThruDxe/AtapiPassThruDxe.inf OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430Dxe.inf -- 2.8.3.windows.1 _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

