+/*++
+
+Copyright (c) 2004 - 2009, Intel Corporation
+Portions copyright (c) 2008-2009 Apple Inc. All rights reserved.
+All rights reserved. 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>
#include <X11/extensions/XShm.h>
#include <X11/keysym.h>
-#include <Guid/PeiPeCoffLoader.h>
#include <Ppi/StatusCode.h>
#include <Library/PeCoffLib.h>
EFI_INPUT_KEY keys[NBR_KEYS];
} UGA_IO_PRIVATE;
-static void
+void
HandleEvents(UGA_IO_PRIVATE *drv);
-static void
+void
fill_shift_mask (struct uga_drv_shift_mask *sm, unsigned long mask)
{
sm->shift = 0;
sm->csize = 8 - sm->size;
}
-static int
+int
TryCreateShmImage(UGA_IO_PRIVATE *drv)
{
drv->image = XShmCreateImage (drv->display, drv->visual,
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;
}
-static
EFI_STATUS
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;
}
-static
EFI_STATUS
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)
return EFI_SUCCESS;
}
-static void
+void
handleKeyEvent(UGA_IO_PRIVATE *drv, XEvent *ev)
{
KeySym keysym;
drv->key_count++;
}
-static void
+void
Redraw(UGA_IO_PRIVATE *drv, UINTN X, UINTN Y, UINTN Width, UINTN Height)
{
if (drv->use_shm)
XFlush(drv->display);
}
-static void
+void
HandleEvent(UGA_IO_PRIVATE *drv, XEvent *ev)
{
switch (ev->type)
}
}
-static void
+void
HandleEvents(UGA_IO_PRIVATE *drv)
{
while (XPending(drv->display) != 0)
}
}
-static
unsigned long
UgaPixelToColor (UGA_IO_PRIVATE *drv, EFI_UGA_PIXEL pixel)
{
| ((pixel.Blue >> drv->b.csize) << drv->b.shift);
}
-static
EFI_UGA_PIXEL
UgaColorToPixel (UGA_IO_PRIVATE *drv, unsigned long val)
{
return res;
}
-static
EFI_STATUS
UgaCheckKey(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo)
{
}
}
-static
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;
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;