]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmulatorPkg/Win/Host/WinGopScreen.c
EmulatorPkg/Win: Use FrameBufferBltLib for BLT operation
[mirror_edk2.git] / EmulatorPkg / Win / Host / WinGopScreen.c
index 2ca51d23d017f6409f33ca794e46017b96071df2..0e1f1ff205aa85f4ccc33a6dab6e3730ef9e52c7 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 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
@@ -193,64 +193,85 @@ WinNtWndSize (
   IN  UINT32                        Height\r
 )\r
 {\r
-  UINT32                            Size;\r
-  GRAPHICS_PRIVATE_DATA             *Private;\r
-  RECT                              Rect;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL     *NewFillLine;\r
+  RETURN_STATUS                        RStatus;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION Info;\r
+  GRAPHICS_PRIVATE_DATA                *Private;\r
+  RECT                                 Rect;\r
+  BITMAPV4HEADER                       *VirtualScreenInfo;\r
+  FRAME_BUFFER_CONFIGURE               *FrameBufferConfigure;\r
+  UINTN                                FrameBufferConfigureSize;\r
 \r
   Private = GRAPHICS_PRIVATE_DATA_FROM_THIS (GraphicsIo);\r
-  Private->Width  = Width;\r
-  Private->Height = Height;\r
-\r
-\r
-  //\r
-  // Free the old buffer. We do not save the content of the old buffer since the\r
-  // screen is to be cleared anyway. Clearing the screen is required by the EFI spec.\r
-  // See UEFI spec -EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode()\r
-  //\r
-  if (Private->VirtualScreenInfo != NULL) {\r
-    HeapFree (GetProcessHeap (), 0, Private->VirtualScreenInfo);\r
-  }\r
 \r
   //\r
   // Allocate DIB frame buffer directly from NT for performance enhancement\r
-  // This buffer is the virtual screen/frame buffer. This buffer is not the\r
-  // same a a frame buffer. The first row of this buffer will be the bottom\r
-  // line of the image. This is an artifact of the way we draw to the screen.\r
+  // This buffer is the virtual screen/frame buffer.\r
   //\r
-  Size = Private->Width * Private->Height * sizeof (RGBQUAD) + sizeof (BITMAPV4HEADER);\r
-  Private->VirtualScreenInfo = HeapAlloc (\r
+  VirtualScreenInfo = HeapAlloc (\r
     GetProcessHeap (),\r
     HEAP_ZERO_MEMORY,\r
-    Size\r
+    Width * Height * sizeof (RGBQUAD) + sizeof (BITMAPV4HEADER)\r
   );\r
+  if (VirtualScreenInfo == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
 \r
   //\r
   // Update the virtual screen info data structure\r
+  // Use negative Height to make sure screen/buffer are using the same coordinate.\r
   //\r
-  Private->VirtualScreenInfo->bV4Size = sizeof (BITMAPV4HEADER);\r
-  Private->VirtualScreenInfo->bV4Width = Private->Width;\r
-  Private->VirtualScreenInfo->bV4Height = Private->Height;\r
-  Private->VirtualScreenInfo->bV4Planes = 1;\r
-  Private->VirtualScreenInfo->bV4BitCount = 32;\r
+  VirtualScreenInfo->bV4Size = sizeof (BITMAPV4HEADER);\r
+  VirtualScreenInfo->bV4Width = Width;\r
+  VirtualScreenInfo->bV4Height = -(LONG)Height;\r
+  VirtualScreenInfo->bV4Planes = 1;\r
+  VirtualScreenInfo->bV4BitCount = 32;\r
   //\r
   // uncompressed\r
   //\r
-  Private->VirtualScreenInfo->bV4V4Compression = BI_RGB;\r
+  VirtualScreenInfo->bV4V4Compression = BI_RGB;\r
+\r
+  Info.HorizontalResolution = Width;\r
+  Info.VerticalResolution   = Height;\r
+  Info.PixelFormat          = PixelBlueGreenRedReserved8BitPerColor;\r
+  Info.PixelsPerScanLine    = Width;\r
+  FrameBufferConfigureSize  = 0;\r
+  RStatus = FrameBufferBltConfigure (VirtualScreenInfo + 1, &Info, NULL, &FrameBufferConfigureSize);\r
+  ASSERT (RStatus == EFI_BUFFER_TOO_SMALL);\r
+  FrameBufferConfigure = AllocatePool (FrameBufferConfigureSize);\r
+  if (FrameBufferConfigure == NULL) {\r
+    HeapFree (GetProcessHeap (), 0, VirtualScreenInfo);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  RStatus = FrameBufferBltConfigure (VirtualScreenInfo + 1, &Info, FrameBufferConfigure, &FrameBufferConfigureSize);\r
+  ASSERT_RETURN_ERROR (RStatus);\r
+\r
+\r
+  if (Private->FrameBufferConfigure != NULL) {\r
+    FreePool (Private->FrameBufferConfigure);\r
+  }\r
+  Private->FrameBufferConfigure = FrameBufferConfigure;\r
 \r
   //\r
-  // The rest of the allocated memory block is the virtual screen buffer\r
+  // Free the old buffer. We do not save the content of the old buffer since the\r
+  // screen is to be cleared anyway. Clearing the screen is required by the EFI spec.\r
+  // See UEFI spec -EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode()\r
   //\r
-  Private->VirtualScreen = (RGBQUAD *)(Private->VirtualScreenInfo + 1);\r
+  if (Private->VirtualScreenInfo != NULL) {\r
+    HeapFree (GetProcessHeap (), 0, Private->VirtualScreenInfo);\r
+  }\r
+  Private->VirtualScreenInfo = VirtualScreenInfo;\r
+\r
+  Private->Width  = Width;\r
+  Private->Height = Height;\r
 \r
   //\r
   // Use the AdjuctWindowRect fuction to calculate the real width and height\r
   // of the new window including the border and caption\r
   //\r
-  Rect.left = 0;\r
-  Rect.top = 0;\r
-  Rect.right = Private->Width;\r
-  Rect.bottom = Private->Height;\r
+  Rect.left   = 0;\r
+  Rect.top    = 0;\r
+  Rect.right  = Width;\r
+  Rect.bottom = Height;\r
 \r
   AdjustWindowRect (&Rect, WS_OVERLAPPEDWINDOW, 0);\r
 \r
@@ -267,16 +288,6 @@ WinNtWndSize (
   //\r
   MoveWindow (Private->WindowHandle, Rect.left, Rect.top, (INT32)Width, (INT32)Height, TRUE);\r
 \r
-  NewFillLine = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * Private->Width);\r
-  if (NewFillLine == NULL) {\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  if (Private->FillLine != NULL) {\r
-    FreePool (Private->FillLine);\r
-  }\r
-\r
-  Private->FillLine = NewFillLine;\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -322,68 +333,22 @@ WinNtWndBlt (
   IN  EMU_GRAPHICS_WINDOWS__BLT_ARGS          *Args\r
 )\r
 {\r
+  RETURN_STATUS                 RStatus;\r
   GRAPHICS_PRIVATE_DATA         *Private;\r
-  UINTN                         DstY;\r
-  UINTN                         SrcY;\r
-  RGBQUAD                       *VScreen;\r
-  RGBQUAD                       *VScreenSrc;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;\r
-  UINTN                         Index;\r
   RECT                          Rect;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *FillPixel;\r
-  UINT32                        VerticalResolution;\r
-  UINT32                        HorizontalResolution;\r
 \r
   Private = GRAPHICS_PRIVATE_DATA_FROM_THIS (GraphicsIo);\r
-\r
-  //\r
-  // We need to fill the Virtual Screen buffer with the blt data.\r
-  // The virtual screen is upside down, as the first row is the bootom row of\r
-  // the image.\r
-  //\r
-  VerticalResolution = Private->VirtualScreenInfo->bV4Height;\r
-  HorizontalResolution = Private->VirtualScreenInfo->bV4Width;\r
-  if (BltOperation == EfiBltVideoToBltBuffer) {\r
-\r
-    for (SrcY = Args->SourceY, DstY = Args->DestinationY; DstY < (Args->Height + Args->DestinationY); SrcY++, DstY++) {\r
-      Blt = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) ((UINT8 *) BltBuffer + (DstY * Args->Delta) + Args->DestinationX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
-      VScreen = &Private->VirtualScreen[(VerticalResolution - SrcY - 1) * HorizontalResolution + Args->SourceX];\r
-      CopyMem (Blt, VScreen, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * Args->Width);\r
-    }\r
-  } else {\r
-    if (BltOperation == EfiBltVideoFill) {\r
-      FillPixel = BltBuffer;\r
-      for (Index = 0; Index < Args->Width; Index++) {\r
-        Private->FillLine[Index] = *FillPixel;\r
-      }\r
-    }\r
-\r
-    for (Index = 0; Index < Args->Height; Index++) {\r
-      if (Args->DestinationY <= Args->SourceY) {\r
-        SrcY  = Args->SourceY + Index;\r
-        DstY  = Args->DestinationY + Index;\r
-      } else {\r
-        SrcY  = Args->SourceY + Args->Height - Index - 1;\r
-        DstY  = Args->DestinationY + Args->Height - Index - 1;\r
-      }\r
-\r
-      VScreen = &Private->VirtualScreen[(VerticalResolution - DstY - 1) * HorizontalResolution + Args->DestinationX];\r
-      switch (BltOperation) {\r
-      case EfiBltBufferToVideo:\r
-        Blt = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) ((UINT8 *) BltBuffer + (SrcY * Args->Delta) + Args->SourceX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
-        CopyMem (VScreen, Blt, Args->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
-        break;\r
-\r
-      case EfiBltVideoToVideo:\r
-        VScreenSrc = &Private->VirtualScreen[(VerticalResolution - SrcY - 1) * HorizontalResolution + Args->SourceX];\r
-        CopyMem (VScreen, VScreenSrc, Args->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
-        break;\r
-\r
-      case EfiBltVideoFill:\r
-        CopyMem (VScreen, Private->FillLine, Args->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
-        break;\r
-      }\r
-    }\r
+  RStatus = FrameBufferBlt (\r
+              Private->FrameBufferConfigure,\r
+              BltBuffer,\r
+              BltOperation,\r
+              Args->SourceX, Args->SourceY,\r
+              Args->DestinationX, Args->DestinationY,\r
+              Args->Width, Args->Height,\r
+              Args->Delta\r
+              );\r
+  if (RETURN_ERROR (RStatus)) {\r
+    return (EFI_STATUS)RStatus;\r
   }\r
 \r
   if (BltOperation != EfiBltVideoToBltBuffer) {\r
@@ -435,21 +400,12 @@ WinNtGopThreadWindowProc (
   )\r
 {\r
   GRAPHICS_PRIVATE_DATA *Private;\r
-  UINTN                 Size;\r
   HDC                   Handle;\r
   PAINTSTRUCT           PaintStruct;\r
   LPARAM                Index;\r
   EFI_INPUT_KEY         Key;\r
   BOOLEAN               AltIsPress;\r
 \r
-  //\r
-  // BugBug - if there are two instances of this DLL in memory (such as is\r
-  // the case for ERM), the correct instance of this function may not be called.\r
-  // This also means that the address of the mTlsIndex value will be wrong, and\r
-  // the value may be wrong too.\r
-  //\r
-\r
-\r
   //\r
   // Use mTlsIndex global to get a Thread Local Storage version of Private.\r
   // This works since each Gop protocol has a unique Private data instance and\r
@@ -460,39 +416,7 @@ WinNtGopThreadWindowProc (
   ASSERT (NULL != Private);\r
 \r
   switch (iMsg) {\r
-  case WM_CREATE:\r
-    Size = Private->Width * Private->Height * sizeof (RGBQUAD);\r
-\r
-    //\r
-    // Allocate DIB frame buffer directly from NT for performance enhancement\r
-    // This buffer is the virtual screen/frame buffer. This buffer is not the\r
-    // same a a frame buffer. The first fow of this buffer will be the bottom\r
-    // line of the image. This is an artifact of the way we draw to the screen.\r
-    //\r
-    Private->VirtualScreenInfo = HeapAlloc (\r
-                                   GetProcessHeap (),\r
-                                   HEAP_ZERO_MEMORY,\r
-                                   Size\r
-                                   );\r
-\r
-    Private->VirtualScreenInfo->bV4Size           = sizeof (BITMAPV4HEADER);\r
-    Private->VirtualScreenInfo->bV4Width          = Private->Width;\r
-    Private->VirtualScreenInfo->bV4Height         = Private->Height;\r
-    Private->VirtualScreenInfo->bV4Planes         = 1;\r
-    Private->VirtualScreenInfo->bV4BitCount       = 32;\r
-    //\r
-    // uncompressed\r
-    //\r
-    Private->VirtualScreenInfo->bV4V4Compression  = BI_RGB;\r
-    Private->VirtualScreen = (RGBQUAD *) (Private->VirtualScreenInfo + 1);\r
-    return 0;\r
-\r
   case WM_PAINT:\r
-    //\r
-    // I have not found a way to convert hwnd into a Private context. So for\r
-    // now we use this API to convert hwnd to Private data.\r
-    //\r
-\r
     Handle = BeginPaint (hwnd, &PaintStruct);\r
 \r
     SetDIBitsToDevice (\r
@@ -505,7 +429,7 @@ WinNtGopThreadWindowProc (
       0,                                          // Source Y\r
       0,                                          // DIB Start Scan Line\r
       Private->Height,                            // Number of scan lines\r
-      Private->VirtualScreen,                     // Address of array of DIB bits\r
+      Private->VirtualScreenInfo + 1,             // Address of array of DIB bits\r
       (BITMAPINFO *) Private->VirtualScreenInfo,  // Address of structure with bitmap info\r
       DIB_RGB_COLORS                              // RGB or palette indexes\r
       );\r
@@ -691,10 +615,6 @@ WinNtGopThreadWinMain (
   // This call will fail after the first time, but thats O.K. since we only need\r
   // WIN_NT_GOP_CLASS_NAME to exist to create the window.\r
   //\r
-  // Note: Multiple instances of this DLL will use the same instance of this\r
-  // Class, including the callback function, unless the Class is unregistered and\r
-  // successfully registered again.\r
-  //\r
   RegisterClassEx (&Private->WindowsClass);\r
 \r
   //\r