]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.c
MdeModulePkg/FrameBufferBltLib: Fix a bug causing display corrupted
[mirror_edk2.git] / MdeModulePkg / Library / FrameBufferBltLib / FrameBufferBltLib.c
index 011d9c52cdfca2a1773728315ea727fd0a1718cb..c88469859b91ff00e8d7c0eecbed00fa7b20e44c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   FrameBufferBltLib - Library to perform blt operations on a frame buffer.\r
 \r
-  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 #include <Library/FrameBufferBltLib.h>\r
 \r
 struct FRAME_BUFFER_CONFIGURE {\r
-  UINTN                           ColorDepth;\r
-  UINTN                           WidthInBytes;\r
-  UINTN                           BytesPerPixel;\r
-  UINTN                           WidthInPixels;\r
-  UINTN                           Height;\r
+  UINT32                          PixelsPerScanLine;\r
+  UINT32                          BytesPerPixel;\r
+  UINT32                          Width;\r
+  UINT32                          Height;\r
   UINT8                           *FrameBuffer;\r
   EFI_GRAPHICS_PIXEL_FORMAT       PixelFormat;\r
   EFI_PIXEL_BITMASK               PixelMasks;\r
@@ -53,7 +52,7 @@ CONST EFI_PIXEL_BITMASK mBgrPixelMasks = {
 VOID\r
 FrameBufferBltLibConfigurePixelFormat (\r
   IN CONST EFI_PIXEL_BITMASK    *BitMask,\r
-  OUT UINT                    *BytesPerPixel,\r
+  OUT UINT32                    *BytesPerPixel,\r
   OUT INT8                      *PixelShl,\r
   OUT INT8                      *PixelShr\r
   )\r
@@ -84,7 +83,7 @@ FrameBufferBltLibConfigurePixelFormat (
   MergedMasks = (UINT32) (MergedMasks | Masks[3]);\r
 \r
   ASSERT (MergedMasks != 0);\r
-  *BytesPerPixel = (UINTN) ((HighBitSet32 (MergedMasks) + 7) / 8);\r
+  *BytesPerPixel = (UINT32) ((HighBitSet32 (MergedMasks) + 7) / 8);\r
   DEBUG ((DEBUG_INFO, "Bytes per pixel: %d\n", *BytesPerPixel));\r
 }\r
 \r
@@ -115,7 +114,7 @@ FrameBufferBltConfigure (
   )\r
 {\r
   CONST EFI_PIXEL_BITMASK                      *BitMask;\r
-  UINT                                       BytesPerPixel;\r
+  UINT32                                       BytesPerPixel;\r
   INT8                                         PixelShl[4];\r
   INT8                                         PixelShr[4];\r
 \r
@@ -145,6 +144,10 @@ FrameBufferBltConfigure (
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
+  if (FrameBufferInfo->PixelsPerScanLine < FrameBufferInfo->HorizontalResolution) {\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
   FrameBufferBltLibConfigurePixelFormat (BitMask, &BytesPerPixel, PixelShl, PixelShr);\r
 \r
   if (*ConfigureSize < sizeof (FRAME_BUFFER_CONFIGURE)\r
@@ -161,12 +164,12 @@ FrameBufferBltConfigure (
   CopyMem (&Configure->PixelMasks, BitMask,  sizeof (*BitMask));\r
   CopyMem (Configure->PixelShl,    PixelShl, sizeof (PixelShl));\r
   CopyMem (Configure->PixelShr,    PixelShr, sizeof (PixelShr));\r
-  Configure->BytesPerPixel = BytesPerPixel;\r
-  Configure->PixelFormat   = FrameBufferInfo->PixelFormat;\r
-  Configure->FrameBuffer   = (UINT8*) FrameBuffer;\r
-  Configure->WidthInPixels = (UINTN) FrameBufferInfo->HorizontalResolution;\r
-  Configure->Height        = (UINTN) FrameBufferInfo->VerticalResolution;\r
-  Configure->WidthInBytes  = Configure->WidthInPixels * Configure->BytesPerPixel;\r
+  Configure->BytesPerPixel     = BytesPerPixel;\r
+  Configure->PixelFormat       = FrameBufferInfo->PixelFormat;\r
+  Configure->FrameBuffer       = (UINT8*) FrameBuffer;\r
+  Configure->Width             = FrameBufferInfo->HorizontalResolution;\r
+  Configure->Height            = FrameBufferInfo->VerticalResolution;\r
+  Configure->PixelsPerScanLine = FrameBufferInfo->PixelsPerScanLine;\r
 \r
   return RETURN_SUCCESS;\r
 }\r
@@ -216,7 +219,7 @@ FrameBufferBltLibVideoFill (
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
-  if (DestinationX + Width > Configure->WidthInPixels) {\r
+  if (DestinationX + Width > Configure->Width) {\r
     DEBUG ((EFI_D_VERBOSE, "VideoFill: Past screen (X)\n"));\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
@@ -269,9 +272,9 @@ FrameBufferBltLibVideoFill (
     }\r
   }\r
 \r
-  if (UseWideFill && (DestinationX == 0) && (Width == Configure->WidthInPixels)) {\r
+  if (UseWideFill && (DestinationX == 0) && (Width == Configure->PixelsPerScanLine)) {\r
     DEBUG ((EFI_D_VERBOSE, "VideoFill (wide, one-shot)\n"));\r
-    Offset = DestinationY * Configure->WidthInPixels;\r
+    Offset = DestinationY * Configure->PixelsPerScanLine;\r
     Offset = Configure->BytesPerPixel * Offset;\r
     Destination = Configure->FrameBuffer + Offset;\r
     SizeInBytes = WidthInBytes * Height;\r
@@ -285,7 +288,7 @@ FrameBufferBltLibVideoFill (
   } else {\r
     LineBufferReady = FALSE;\r
     for (IndexY = DestinationY; IndexY < (Height + DestinationY); IndexY++) {\r
-      Offset = (IndexY * Configure->WidthInPixels) + DestinationX;\r
+      Offset = (IndexY * Configure->PixelsPerScanLine) + DestinationX;\r
       Offset = Configure->BytesPerPixel * Offset;\r
       Destination = Configure->FrameBuffer + Offset;\r
 \r
@@ -369,7 +372,7 @@ FrameBufferBltLibVideoToBltBuffer (
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
-  if (SourceX + Width > Configure->WidthInPixels) {\r
+  if (SourceX + Width > Configure->Width) {\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
@@ -395,7 +398,7 @@ FrameBufferBltLibVideoToBltBuffer (
        DstY < (Height + DestinationY);\r
        SrcY++, DstY++) {\r
 \r
-    Offset = (SrcY * Configure->WidthInPixels) + SourceX;\r
+    Offset = (SrcY * Configure->PixelsPerScanLine) + SourceX;\r
     Offset = Configure->BytesPerPixel * Offset;\r
     Source = Configure->FrameBuffer + Offset;\r
 \r
@@ -477,7 +480,7 @@ FrameBufferBltLibBufferToVideo (
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
-  if (DestinationX + Width > Configure->WidthInPixels) {\r
+  if (DestinationX + Width > Configure->Width) {\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
@@ -500,7 +503,7 @@ FrameBufferBltLibBufferToVideo (
        SrcY < (Height + SourceY);\r
        SrcY++, DstY++) {\r
 \r
-    Offset = (DstY * Configure->WidthInPixels) + DestinationX;\r
+    Offset = (DstY * Configure->PixelsPerScanLine) + DestinationX;\r
     Offset = Configure->BytesPerPixel * Offset;\r
     Destination = Configure->FrameBuffer + Offset;\r
 \r
@@ -573,7 +576,7 @@ FrameBufferBltLibVideoToVideo (
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
-  if (SourceX + Width > Configure->WidthInPixels) {\r
+  if (SourceX + Width > Configure->Width) {\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
@@ -581,7 +584,7 @@ FrameBufferBltLibVideoToVideo (
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
-  if (DestinationX + Width > Configure->WidthInPixels) {\r
+  if (DestinationX + Width > Configure->Width) {\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
@@ -591,15 +594,15 @@ FrameBufferBltLibVideoToVideo (
 \r
   WidthInBytes = Width * Configure->BytesPerPixel;\r
 \r
-  Offset = (SourceY * Configure->WidthInPixels) + SourceX;\r
+  Offset = (SourceY * Configure->PixelsPerScanLine) + SourceX;\r
   Offset = Configure->BytesPerPixel * Offset;\r
   Source = Configure->FrameBuffer + Offset;\r
 \r
-  Offset = (DestinationY * Configure->WidthInPixels) + DestinationX;\r
+  Offset = (DestinationY * Configure->PixelsPerScanLine) + DestinationX;\r
   Offset = Configure->BytesPerPixel * Offset;\r
   Destination = Configure->FrameBuffer + Offset;\r
 \r
-  LineStride = Configure->WidthInBytes;\r
+  LineStride = Configure->BytesPerPixel * Configure->PixelsPerScanLine;\r
   if (Destination > Source) {\r
     //\r
     // Copy from last line to avoid source is corrupted by copying\r