]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Universal/Console/ConSplitter/Dxe/ConSplitterGraphics.c
Add check whether input parameter is NULL before call freepool API defined in MDE.
[mirror_edk2.git] / EdkModulePkg / Universal / Console / ConSplitter / Dxe / ConSplitterGraphics.c
index cec8adb2fb8e30e02e192257488ec38b5277895c..2f60e11c40bb67eb431529a2f40ad485d8a77845 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2006, Intel Corporation                                                         \r
+Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
 All rights reserved. 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
@@ -116,6 +116,13 @@ ConSpliterConsoleControlSetMode (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  //\r
+  // Judge current mode with wanted mode at first.\r
+  // \r
+  if (Private->ConsoleOutputMode == Mode) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
   Supported   = FALSE;\r
   TextAndGop  = &Private->TextOutList[0];\r
   for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++, TextAndGop++) {\r
@@ -185,7 +192,6 @@ ConSpliterGraphicsOutputQueryMode (
 --*/\r
 {\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private;\r
-  EFI_STATUS                      Status;\r
   TEXT_OUT_GOP_MODE               *Mode;\r
 \r
   if (This == NULL || Info == NULL || SizeOfInfo == NULL || ModeNumber >= This->Mode->MaxMode) {\r
@@ -201,13 +207,10 @@ ConSpliterGraphicsOutputQueryMode (
     return EFI_NOT_STARTED;\r
   }\r
 \r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION),\r
-                  (VOID **) Info\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
+  *Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r
+\r
+  if (*Info == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
   *SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
@@ -275,7 +278,7 @@ Routine Description:
   // Free the old version\r
   //\r
   if (Private->GraphicsOutputBlt != NULL) {\r
-    gBS->FreePool (Private->GraphicsOutputBlt);\r
+    FreePool (Private->GraphicsOutputBlt);\r
   }\r
 \r
   //\r
@@ -309,10 +312,10 @@ Routine Description:
           return Status;\r
         }\r
         if ((Info->HorizontalResolution == Mode->HorizontalResolution) && (Info->VerticalResolution == Mode->VerticalResolution)) {\r
-          gBS->FreePool (Info);\r
+          FreePool (Info);\r
           break;\r
         }\r
-        gBS->FreePool (Info);\r
+        FreePool (Info);\r
       }\r
 \r
       Status = GraphicsOutput->SetMode (GraphicsOutput, (UINT32) NumberIndex);\r
@@ -371,6 +374,7 @@ DevNullGraphicsOutputBlt (
   )\r
 {\r
   UINTN                         SrcY;\r
+  BOOLEAN                       Forward; \r
   UINTN                         Index;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltPtr;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ScreenPtr;\r
@@ -427,9 +431,23 @@ DevNullGraphicsOutputBlt (
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    ScreenPtr = &Private->GraphicsOutputBlt[DestinationY * HorizontalResolution + DestinationX];\r
-    SrcY      = SourceY;\r
-    while (Height) {\r
+    if ((BltOperation == EfiBltVideoToVideo) && (DestinationY > SourceY)) {\r
+      //\r
+      // Copy backwards, only care the Video to Video Blt\r
+      //\r
+      ScreenPtr = &Private->GraphicsOutputBlt[(DestinationY + Height - 1) * HorizontalResolution + DestinationX];\r
+      SrcY      = SourceY + Height - 1;\r
+      Forward   = FALSE;\r
+    } else {\r
+      //\r
+      // Copy forwards, for other cases\r
+      //\r
+      ScreenPtr = &Private->GraphicsOutputBlt[DestinationY * HorizontalResolution + DestinationX];\r
+      SrcY      = SourceY;\r
+      Forward   = TRUE;\r
+    }\r
+\r
+    while (Height != 0) {\r
       if (BltOperation == EfiBltVideoFill) {\r
         for (Index = 0; Index < Width; Index++) {\r
           ScreenPtr[Index] = *BltBuffer;\r
@@ -444,8 +462,13 @@ DevNullGraphicsOutputBlt (
         CopyMem (ScreenPtr, BltPtr, Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
       }\r
 \r
-      ScreenPtr += HorizontalResolution;\r
-      SrcY++;\r
+      if (Forward) {\r
+        ScreenPtr += HorizontalResolution;\r
+        SrcY ++;\r
+      } else {\r
+        ScreenPtr -= HorizontalResolution;\r
+        SrcY --;\r
+      }\r
       Height--;\r
     }\r
   }\r
@@ -727,7 +750,7 @@ ConSpliterUgaDrawSetMode (
   //\r
   // Free the old version\r
   //\r
-  gBS->FreePool (Private->UgaBlt);\r
+  FreePool (Private->UgaBlt);\r
 \r
   //\r
   // Allocate the virtual Blt buffer\r
@@ -785,6 +808,7 @@ DevNullUgaBlt (
   )\r
 {\r
   UINTN         SrcY;\r
+  BOOLEAN       Forward;\r
   UINTN         Index;\r
   EFI_UGA_PIXEL *BltPtr;\r
   EFI_UGA_PIXEL *ScreenPtr;\r
@@ -841,9 +865,23 @@ DevNullUgaBlt (
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    ScreenPtr = &Private->UgaBlt[DestinationY * HorizontalResolution + DestinationX];\r
-    SrcY      = SourceY;\r
-    while (Height) {\r
+    if ((BltOperation == EfiUgaVideoToVideo) && (DestinationY > SourceY)) {\r
+      //\r
+      // Copy backwards, only care the Video to Video Blt\r
+      //\r
+      ScreenPtr = &Private->UgaBlt[(DestinationY + Height - 1) * HorizontalResolution + DestinationX];\r
+      SrcY      = SourceY + Height - 1;\r
+      Forward   = FALSE;\r
+    } else {\r
+      //\r
+      // Copy forwards, for other cases\r
+      //\r
+      ScreenPtr = &Private->UgaBlt[DestinationY * HorizontalResolution + DestinationX];\r
+      SrcY      = SourceY;\r
+      Forward   = TRUE;\r
+    }\r
+\r
+    while (Height != 0) {\r
       if (BltOperation == EfiUgaVideoFill) {\r
         for (Index = 0; Index < Width; Index++) {\r
           ScreenPtr[Index] = *BltBuffer;\r
@@ -858,8 +896,13 @@ DevNullUgaBlt (
         CopyMem (ScreenPtr, BltPtr, Width * sizeof (EFI_UGA_PIXEL));\r
       }\r
 \r
-      ScreenPtr += HorizontalResolution;\r
-      SrcY++;\r
+      if (Forward) {\r
+        ScreenPtr += HorizontalResolution;\r
+        SrcY ++;\r
+      } else {\r
+        ScreenPtr -= HorizontalResolution;\r
+        SrcY --;\r
+      }\r
       Height--;\r
     }\r
   }\r
@@ -1271,8 +1314,10 @@ DevNullTextOutSetMode (
     Private->TextOutMode.Mode = (INT32) ModeNumber;\r
     Private->DevNullColumns   = Column;\r
     Private->DevNullRows      = Row;\r
-\r
-    gBS->FreePool (Private->DevNullScreen);\r
+    \r
+    if (Private->DevNullScreen != NULL) {\r
+      FreePool (Private->DevNullScreen);\r
+    }\r
 \r
     Size                    = (Row * (Column + 1)) * sizeof (CHAR16);\r
     Private->DevNullScreen  = AllocateZeroPool (Size);\r
@@ -1280,7 +1325,9 @@ DevNullTextOutSetMode (
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
-    gBS->FreePool (Private->DevNullAttributes);\r
+    if (Private->DevNullAttributes != NULL) {\r
+      FreePool (Private->DevNullAttributes);\r
+    }\r
 \r
     Size                        = Row * Column * sizeof (INT32);\r
     Private->DevNullAttributes  = AllocateZeroPool (Size);\r
@@ -1557,7 +1604,7 @@ DevNullSyncGopStdOut (
     }\r
   }\r
 \r
-  gBS->FreePool (Buffer);\r
+  FreePool (Buffer);\r
 \r
   return ReturnStatus;\r
 }\r