]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/FrameBufferBltLib: Use dynamic allocated line buffer
authorRuiyu Ni <ruiyu.ni@intel.com>
Wed, 11 Jan 2017 07:16:39 +0000 (15:16 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Tue, 24 Jan 2017 07:06:39 +0000 (15:06 +0800)
https://bugzilla.tianocore.org/show_bug.cgi?id=339

The patch uses dynamic allocated line buffer to reduce memory usage
of frame buffer configure. (Original implementation uses 0x4000
bytes for line buffer.)

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.c

index 5f6eddcb389eb0e42ca9d9d3dba0c3466d9c4d88..011d9c52cdfca2a1773728315ea727fd0a1718cb 100644 (file)
@@ -26,12 +26,12 @@ struct FRAME_BUFFER_CONFIGURE {
   UINTN                           BytesPerPixel;\r
   UINTN                           WidthInPixels;\r
   UINTN                           Height;\r
-  UINT8                           LineBuffer[SIZE_4KB * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)];\r
   UINT8                           *FrameBuffer;\r
   EFI_GRAPHICS_PIXEL_FORMAT       PixelFormat;\r
   EFI_PIXEL_BITMASK               PixelMasks;\r
   INT8                            PixelShl[4]; // R-G-B-Rsvd\r
   INT8                            PixelShr[4]; // R-G-B-Rsvd\r
+  UINT8                           LineBuffer[0];\r
 };\r
 \r
 CONST EFI_PIXEL_BITMASK mRgbPixelMasks = {\r
@@ -123,15 +123,6 @@ FrameBufferBltConfigure (
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
-  if (*ConfigureSize < sizeof (FRAME_BUFFER_CONFIGURE)) {\r
-    *ConfigureSize = sizeof (FRAME_BUFFER_CONFIGURE);\r
-    return RETURN_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  if (Configure == NULL) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
-\r
   switch (FrameBufferInfo->PixelFormat) {\r
   case PixelRedGreenBlueReserved8BitPerColor:\r
     BitMask = &mRgbPixelMasks;\r
@@ -156,6 +147,17 @@ FrameBufferBltConfigure (
 \r
   FrameBufferBltLibConfigurePixelFormat (BitMask, &BytesPerPixel, PixelShl, PixelShr);\r
 \r
+  if (*ConfigureSize < sizeof (FRAME_BUFFER_CONFIGURE)\r
+                     + FrameBufferInfo->HorizontalResolution * BytesPerPixel) {\r
+    *ConfigureSize = sizeof (FRAME_BUFFER_CONFIGURE)\r
+                   + FrameBufferInfo->HorizontalResolution * BytesPerPixel;\r
+    return RETURN_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+  if (Configure == NULL) {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+\r
   CopyMem (&Configure->PixelMasks, BitMask,  sizeof (*BitMask));\r
   CopyMem (Configure->PixelShl,    PixelShl, sizeof (PixelShl));\r
   CopyMem (Configure->PixelShr,    PixelShr, sizeof (PixelShr));\r
@@ -166,8 +168,6 @@ FrameBufferBltConfigure (
   Configure->Height        = (UINTN) FrameBufferInfo->VerticalResolution;\r
   Configure->WidthInBytes  = Configure->WidthInPixels * Configure->BytesPerPixel;\r
 \r
-  ASSERT (Configure->WidthInBytes < sizeof (Configure->LineBuffer));\r
-\r
   return RETURN_SUCCESS;\r
 }\r
 \r