]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/FrameBufferBltLib: Refine ConfigurePixelBitMaskFormat
authorRuiyu Ni <ruiyu.ni@intel.com>
Wed, 11 Jan 2017 07:06:25 +0000 (15:06 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Tue, 24 Jan 2017 07:06:38 +0000 (15:06 +0800)
https://bugzilla.tianocore.org/show_bug.cgi?id=339
The patch refines ConfigurePixelBitMaskFormat() to prepare the
enhancement in next commit: Enhance this library to use dynamic
allocated line buffer to reduce memory usage of frame buffer
configure.

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 c9bb206ee8d02985eae1ba0228ab4308f3c99d88..5f6eddcb389eb0e42ca9d9d3dba0c3466d9c4d88 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   FrameBufferBltLib - Library to perform blt operations on a frame buffer.\r
 \r
-  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2007 - 2017, 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
@@ -30,8 +30,8 @@ struct FRAME_BUFFER_CONFIGURE {
   UINT8                           *FrameBuffer;\r
   EFI_GRAPHICS_PIXEL_FORMAT       PixelFormat;\r
   EFI_PIXEL_BITMASK               PixelMasks;\r
-  INTN                            PixelShl[4]; // R-G-B-Rsvd\r
-  INTN                            PixelShr[4]; // R-G-B-Rsvd\r
+  INT8                            PixelShl[4]; // R-G-B-Rsvd\r
+  INT8                            PixelShr[4]; // R-G-B-Rsvd\r
 };\r
 \r
 CONST EFI_PIXEL_BITMASK mRgbPixelMasks = {\r
@@ -45,43 +45,47 @@ CONST EFI_PIXEL_BITMASK mBgrPixelMasks = {
 /**\r
   Initialize the bit mask in frame buffer configure.\r
 \r
-  @param Configure  The frame buffer configure.\r
-  @param BitMask    The bit mask of pixel.\r
+  @param BitMask       The bit mask of pixel.\r
+  @param BytesPerPixel Size in bytes of pixel.\r
+  @param PixelShl      Left shift array.\r
+  @param PixelShr      Right shift array.\r
 **/\r
 VOID\r
-ConfigurePixelBitMaskFormat (\r
-  IN FRAME_BUFFER_CONFIGURE     *Configure,\r
-  IN CONST EFI_PIXEL_BITMASK    *BitMask\r
+FrameBufferBltLibConfigurePixelFormat (\r
+  IN CONST EFI_PIXEL_BITMASK    *BitMask,\r
+  OUT UINTN                     *BytesPerPixel,\r
+  OUT INT8                      *PixelShl,\r
+  OUT INT8                      *PixelShr\r
   )\r
 {\r
-  UINTN   Loop;\r
+  UINT8   Index;\r
   UINT32  *Masks;\r
   UINT32  MergedMasks;\r
 \r
+  ASSERT (BytesPerPixel != NULL);\r
+\r
   MergedMasks = 0;\r
   Masks = (UINT32*) BitMask;\r
-  for (Loop = 0; Loop < 3; Loop++) {\r
-    ASSERT ((Loop == 3) || (Masks[Loop] != 0));\r
-    ASSERT ((MergedMasks & Masks[Loop]) == 0);\r
-    Configure->PixelShl[Loop] = HighBitSet32 (Masks[Loop]) - 23 + (Loop * 8);\r
-    if (Configure->PixelShl[Loop] < 0) {\r
-      Configure->PixelShr[Loop] = -Configure->PixelShl[Loop];\r
-      Configure->PixelShl[Loop] = 0;\r
+  for (Index = 0; Index < 3; Index++) {\r
+    ASSERT ((MergedMasks & Masks[Index]) == 0);\r
+\r
+    PixelShl[Index] = (INT8) HighBitSet32 (Masks[Index]) - 23 + (Index * 8);\r
+    if (PixelShl[Index] < 0) {\r
+      PixelShr[Index] = -PixelShl[Index];\r
+      PixelShl[Index] = 0;\r
     } else {\r
-      Configure->PixelShr[Loop] = 0;\r
+      PixelShr[Index] = 0;\r
     }\r
-    MergedMasks = (UINT32) (MergedMasks | Masks[Loop]);\r
-    DEBUG ((EFI_D_VERBOSE, "%d: shl:%d shr:%d mask:%x\n", Loop,\r
-            Configure->PixelShl[Loop], Configure->PixelShr[Loop], Masks[Loop]));\r
+    DEBUG ((DEBUG_INFO, "%d: shl:%d shr:%d mask:%x\n", Index,\r
+            PixelShl[Index], PixelShr[Index], Masks[Index]));\r
+\r
+    MergedMasks = (UINT32) (MergedMasks | Masks[Index]);\r
   }\r
   MergedMasks = (UINT32) (MergedMasks | Masks[3]);\r
 \r
   ASSERT (MergedMasks != 0);\r
-  Configure->BytesPerPixel = (UINTN) ((HighBitSet32 (MergedMasks) + 7) / 8);\r
-\r
-  DEBUG ((EFI_D_VERBOSE, "Bytes per pixel: %d\n", Configure->BytesPerPixel));\r
-\r
-  CopyMem (&Configure->PixelMasks, BitMask, sizeof (*BitMask));\r
+  *BytesPerPixel = (UINTN) ((HighBitSet32 (MergedMasks) + 7) / 8);\r
+  DEBUG ((DEBUG_INFO, "Bytes per pixel: %d\n", *BytesPerPixel));\r
 }\r
 \r
 /**\r
@@ -110,6 +114,11 @@ FrameBufferBltConfigure (
   IN OUT UINTN                                 *ConfigureSize\r
   )\r
 {\r
+  CONST EFI_PIXEL_BITMASK                      *BitMask;\r
+  UINTN                                        BytesPerPixel;\r
+  INT8                                         PixelShl[4];\r
+  INT8                                         PixelShr[4];\r
+\r
   if (ConfigureSize == NULL) {\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
@@ -125,15 +134,15 @@ FrameBufferBltConfigure (
 \r
   switch (FrameBufferInfo->PixelFormat) {\r
   case PixelRedGreenBlueReserved8BitPerColor:\r
-    ConfigurePixelBitMaskFormat (Configure, &mRgbPixelMasks);\r
+    BitMask = &mRgbPixelMasks;\r
     break;\r
 \r
   case PixelBlueGreenRedReserved8BitPerColor:\r
-    ConfigurePixelBitMaskFormat (Configure, &mBgrPixelMasks);\r
+    BitMask = &mBgrPixelMasks;\r
     break;\r
 \r
   case PixelBitMask:\r
-    ConfigurePixelBitMaskFormat (Configure, &(FrameBufferInfo->PixelInformation));\r
+    BitMask = &FrameBufferInfo->PixelInformation;\r
     break;\r
 \r
   case PixelBltOnly:\r
@@ -145,6 +154,12 @@ FrameBufferBltConfigure (
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
+  FrameBufferBltLibConfigurePixelFormat (BitMask, &BytesPerPixel, PixelShl, PixelShr);\r
+\r
+  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