]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/FrameBufferBltLib: Fix a bug causing display corrupted
authorRuiyu Ni <ruiyu.ni@intel.com>
Mon, 15 Jan 2018 03:43:33 +0000 (11:43 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Tue, 16 Jan 2018 05:26:55 +0000 (13:26 +0800)
The Graphics Output Protocol's mode information specifies the
PixelsPerScanLine property. Most of the time this is identical to
HorizontalResolution. However, due to alignment requirements etc. it
may be slightly larger. I.e. each scan line will have some "pixels"
that are not visible on the screen but consume space in the frame
buffer.

If the graphics output protocol correctly initializes
HorizontalResolution to 1366 and PixelsPerScanLine to 1376. As a
result the graphics output is broken.

If setting HorizontalResolution to 1376 instead, the output is fine
(except for 10 invisible pixels on the right of the screen).

The patch fixes this bug by using PixelsPerScanLine when calculating
the line width.

Contributed-under: TianoCore Contribution Agreement 1.1
Reported-by: Christian Ehrhardt <ehrhardt@genua.de>
Signed-off-by: Christian Ehrhardt <ehrhardt@genua.de>
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Christian Ehrhardt <ehrhardt@genua.de>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Tested-by: Christian Ehrhardt <ehrhardt@genua.de>
MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.c

index 3078fe6254c57e7a5cd511d0fdff090c104f61ee..c88469859b91ff00e8d7c0eecbed00fa7b20e44c 100644 (file)
@@ -21,9 +21,9 @@
 #include <Library/FrameBufferBltLib.h>\r
 \r
 struct FRAME_BUFFER_CONFIGURE {\r
-  UINT32                          WidthInBytes;\r
+  UINT32                          PixelsPerScanLine;\r
   UINT32                          BytesPerPixel;\r
-  UINT32                          WidthInPixels;\r
+  UINT32                          Width;\r
   UINT32                          Height;\r
   UINT8                           *FrameBuffer;\r
   EFI_GRAPHICS_PIXEL_FORMAT       PixelFormat;\r
@@ -144,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
@@ -160,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 = FrameBufferInfo->HorizontalResolution;\r
-  Configure->Height        = 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
@@ -215,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
@@ -268,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
@@ -284,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
@@ -368,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
@@ -394,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
@@ -476,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
@@ -499,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
@@ -572,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
@@ -580,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
@@ -590,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