]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UnixPkg/Sec/UgaX11.c
Port UnixPkg to also support X64. Currently only supports Unix x86_64 ABI. In the...
[mirror_edk2.git] / UnixPkg / Sec / UgaX11.c
index a6cac78c51be9a9b5ec045ec3872a4181b1a9ab9..f43c7b44a24208ea0475614c7c9ebaaa3aa83e43 100644 (file)
@@ -1,6 +1,19 @@
+/*++
+
+Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
+Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+This program and the accompanying materials                          
+are licensed and made available under the terms and conditions of the BSD License         
+which accompanies this distribution.  The full text of the license may be found at        
+http://opensource.org/licenses/bsd-license.php                                            
+                                                                                          
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
+
+--*/
+
 #include <sys/ipc.h>
 #include <sys/shm.h>
-#include <sys/dir.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -110,31 +123,35 @@ TryCreateShmImage(UGA_IO_PRIVATE *drv)
   drv->xshm_info.shmid = shmget
                           (IPC_PRIVATE, drv->image->bytes_per_line * drv->image->height,
                           IPC_CREAT | 0777);
-  if (drv->xshm_info.shmid < 0)
-    {
-      XDestroyImage(drv->image);
-      return 0;
-    }
+  if (drv->xshm_info.shmid < 0) {
+    XDestroyImage(drv->image);
+    return 0;
+  }
       
   drv->image_data = shmat (drv->xshm_info.shmid, NULL, 0);
-  if(!drv->image_data)
-    {
-      shmctl (drv->xshm_info.shmid, IPC_RMID, NULL);
-      XDestroyImage(drv->image);
-      return 0;
-    }
+  if(!drv->image_data) {
+    shmctl (drv->xshm_info.shmid, IPC_RMID, NULL);
+    XDestroyImage(drv->image);
+    return 0;
+  }
+  
+#ifndef __APPLE__  
+  //
+  // This closes shared memory in real time on OS X. Only closes after folks quit using
+  // it on Linux. 
+  //
   /* Can this fail ?  */
   shmctl (drv->xshm_info.shmid, IPC_RMID, NULL);
+#endif
 
   drv->xshm_info.shmaddr = (char*)drv->image_data;
   drv->image->data = (char*)drv->image_data;
 
-  if (!XShmAttach (drv->display, &drv->xshm_info))
-    {
-      shmdt (drv->image_data);
-      XDestroyImage(drv->image);
-      return 0;
-    }
+  if (!XShmAttach (drv->display, &drv->xshm_info)) {
+    shmdt (drv->image_data);
+    XDestroyImage(drv->image);
+    return 0;
+  }
   return 1;
 }
 
@@ -157,6 +174,12 @@ UgaClose (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo)
     }
   XDestroyWindow(drv->display, drv->win);
   XCloseDisplay(drv->display);
+  
+#ifdef __APPLE__
+  // Free up the shared memory
+  shmctl (drv->xshm_info.shmid, IPC_RMID, NULL);
+#endif
+  
   free(drv);
   return EFI_SUCCESS;
 }
@@ -170,6 +193,7 @@ UgaSize(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, UINT32 Width, UINT32 Height)
   /* Destroy current buffer if created.  */
   if (drv->image != NULL)
     {
+      /* Before destroy buffer, need to make sure the buffer available for access. */
       XDestroyImage(drv->image);
 
       if (drv->use_shm)
@@ -349,9 +373,10 @@ UgaCheckKey(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo)
 {
   UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo;
   HandleEvents(drv);
-  if (drv->key_count != 0)
+  
+  if (drv->key_count != 0) {
     return EFI_SUCCESS;
-  else {
+  else {
     /* EFI is certainly polling.  Be CPU-friendly.  */
     msSleep (20);
     return EFI_NOT_READY;
@@ -359,7 +384,7 @@ UgaCheckKey(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo)
 }
 
 EFI_STATUS
-UgaGetKey(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, EFI_INPUT_KEY *key)
+UgaGetKey (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, EFI_INPUT_KEY *key)
 {
   UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo;
   EFI_STATUS status;
@@ -533,16 +558,45 @@ UgaCreate (EFI_UNIX_UGA_IO_PROTOCOL **Uga, CONST CHAR16 *Title)
   char *display_name = NULL;
   int title_len;
 
-  drv = (UGA_IO_PRIVATE *)
-    calloc (1, sizeof (UGA_IO_PRIVATE));
+  drv = (UGA_IO_PRIVATE *)calloc (1, sizeof (UGA_IO_PRIVATE));
   if (drv == NULL)
     return EFI_OUT_OF_RESOURCES;
 
+#ifdef __APPLE__
+//
+//
+//
+EFI_STATUS EFIAPI GasketUgaClose (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo);
+EFI_STATUS EFIAPI GasketUgaSize (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, UINT32 Width, UINT32 Height);
+EFI_STATUS EFIAPI GasketUgaCheckKey (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo);
+EFI_STATUS EFIAPI GasketUgaGetKey (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, EFI_INPUT_KEY *key);
+EFI_STATUS EFIAPI GasketUgaBlt (
+   EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
+   IN  EFI_UGA_PIXEL                           *BltBuffer OPTIONAL,
+   IN  EFI_UGA_BLT_OPERATION                   BltOperation,
+   IN  UINTN                                   SourceX,
+   IN  UINTN                                   SourceY,
+   IN  UINTN                                   DestinationX,
+   IN  UINTN                                   DestinationY,
+   IN  UINTN                                   Width,
+   IN  UINTN                                   Height,
+   IN  UINTN                                   Delta OPTIONAL
+   );
+
+  drv->UgaIo.UgaClose    = GasketUgaClose; 
+  drv->UgaIo.UgaSize     = GasketUgaSize;
+  drv->UgaIo.UgaCheckKey = GasketUgaCheckKey;
+  drv->UgaIo.UgaGetKey   = GasketUgaGetKey;
+  drv->UgaIo.UgaBlt      = GasketUgaBlt;
+#else
   drv->UgaIo.UgaClose = UgaClose;
   drv->UgaIo.UgaSize = UgaSize;
   drv->UgaIo.UgaCheckKey = UgaCheckKey;
   drv->UgaIo.UgaGetKey = UgaGetKey;
   drv->UgaIo.UgaBlt = UgaBlt;
+#endif
+  
+  
 
   drv->key_count = 0;
   drv->key_rd = 0;
@@ -578,8 +632,8 @@ UgaCreate (EFI_UNIX_UGA_IO_PROTOCOL **Uga, CONST CHAR16 *Title)
     XStoreName (drv->display, drv->win, title);
   }
 
-  XSelectInput (drv->display, drv->win,
-                 ExposureMask | KeyPressMask);
+  XSelectInput (drv->display, drv->win, ExposureMask | KeyPressMask);
+  
   drv->gc = DefaultGC (drv->display, drv->screen);
 
   *Uga = (EFI_UNIX_UGA_IO_PROTOCOL *)drv;