InOsEmuPkg: Clean up coding standards.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11839 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
andrewfish 2011-06-16 18:28:12 +00:00
parent 92a2f8ea68
commit bfa084fad9
3 changed files with 418 additions and 370 deletions

View File

@ -255,21 +255,10 @@ EmuBlockIoError (
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
break; break;
} }
/*
if (ReinstallBlockIoFlag) {
Private->EmuBlockIo->Reset (&Private->EmuBlockIo, FALSE);
gBS->ReinstallProtocolInterface (
Private->EfiHandle,
&gEfiBlockIoProtocolGuid,
BlockIo,
BlockIo
);
}
*/
return Status; return Status;
} }
EFI_STATUS EFI_STATUS
EmuBlockIoReadWriteCommon ( EmuBlockIoReadWriteCommon (
IN EMU_BLOCK_IO_PRIVATE *Private, IN EMU_BLOCK_IO_PRIVATE *Private,
@ -567,21 +556,6 @@ EmuBlockIoReset (
IN EMU_BLOCK_IO_PROTOCOL *This, IN EMU_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification IN BOOLEAN ExtendedVerification
) )
/*++
Routine Description:
Reset the Block Device.
Arguments:
This - Protocol instance pointer.
ExtendedVerification - Driver may perform diagnostics on reset.
Returns:
EFI_SUCCESS - The device was reset.
EFI_DEVICE_ERROR - The device is not functioning properly and could
not be reset.
**/
{ {
EMU_BLOCK_IO_PRIVATE *Private; EMU_BLOCK_IO_PRIVATE *Private;

View File

@ -298,10 +298,11 @@ main (
EFI_PHYSICAL_ADDRESS * EFI_PHYSICAL_ADDRESS *
MapMemory ( MapMemory (
INTN fd, IN INTN fd,
UINT64 length, IN UINT64 length,
INTN prot, IN INTN prot,
INTN flags) IN INTN flags
)
{ {
STATIC UINTN base = 0x40000000; STATIC UINTN base = 0x40000000;
CONST UINTN align = (1 << 24); CONST UINTN align = (1 << 24);
@ -786,7 +787,6 @@ CountSeperatorsInString (
EFI_STATUS EFI_STATUS
EFIAPI
SecImageRead ( SecImageRead (
IN VOID *FileHandle, IN VOID *FileHandle,
IN UINTN FileOffset, IN UINTN FileOffset,

View File

@ -28,7 +28,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#define KEYSYM_LOWER 0 #define KEYSYM_LOWER 0
#define KEYSYM_UPPER 1 #define KEYSYM_UPPER 1
/* XQueryPointer */
struct uga_drv_shift_mask { struct uga_drv_shift_mask {
unsigned char shift; unsigned char shift;
@ -41,7 +40,7 @@ typedef struct {
EMU_GRAPHICS_WINDOW_PROTOCOL GraphicsIo; EMU_GRAPHICS_WINDOW_PROTOCOL GraphicsIo;
Display *display; Display *display;
int screen; /* values for window_size in main */ int screen; // values for window_size in main
Window win; Window win;
GC gc; GC gc;
Visual *visual; Visual *visual;
@ -58,6 +57,7 @@ typedef struct {
int use_shm; int use_shm;
XShmSegmentInfo xshm_info; XShmSegmentInfo xshm_info;
XImage *image; XImage *image;
char *Title;
unsigned int key_rd; unsigned int key_rd;
unsigned int key_wr; unsigned int key_wr;
@ -77,20 +77,23 @@ typedef struct {
} GRAPHICS_IO_PRIVATE; } GRAPHICS_IO_PRIVATE;
void void
HandleEvents(GRAPHICS_IO_PRIVATE *drv); HandleEvents(
IN GRAPHICS_IO_PRIVATE *Drv
);
void void
fill_shift_mask (struct uga_drv_shift_mask *sm, unsigned long mask) fill_shift_mask (
IN struct uga_drv_shift_mask *sm,
IN unsigned long mask
)
{ {
sm->shift = 0; sm->shift = 0;
sm->size = 0; sm->size = 0;
while ((mask & 1) == 0) while ((mask & 1) == 0) {
{
mask >>= 1; mask >>= 1;
sm->shift++; sm->shift++;
} }
while (mask & 1) while (mask & 1) {
{
sm->size++; sm->size++;
mask >>= 1; mask >>= 1;
} }
@ -99,39 +102,43 @@ fill_shift_mask (struct uga_drv_shift_mask *sm, unsigned long mask)
int int
TryCreateShmImage ( TryCreateShmImage (
IN GRAPHICS_IO_PRIVATE *drv IN GRAPHICS_IO_PRIVATE *Drv
) )
{ {
drv->image = XShmCreateImage (drv->display, drv->visual, Drv->image = XShmCreateImage (
drv->depth, ZPixmap, NULL, &drv->xshm_info, Drv->display, Drv->visual,
drv->width, drv->height); Drv->depth, ZPixmap, NULL, &Drv->xshm_info,
if (drv->image == NULL) Drv->width, Drv->height
);
if (Drv->image == NULL) {
return 0; return 0;
}
switch (drv->image->bitmap_unit) { switch (Drv->image->bitmap_unit) {
case 32: case 32:
drv->pixel_shift = 2; Drv->pixel_shift = 2;
break; break;
case 16: case 16:
drv->pixel_shift = 1; Drv->pixel_shift = 1;
break; break;
case 8: case 8:
drv->pixel_shift = 0; Drv->pixel_shift = 0;
break; break;
} }
drv->xshm_info.shmid = shmget Drv->xshm_info.shmid = shmget (
(IPC_PRIVATE, drv->image->bytes_per_line * drv->image->height, IPC_PRIVATE, Drv->image->bytes_per_line * Drv->image->height,
IPC_CREAT | 0777); IPC_CREAT | 0777
if (drv->xshm_info.shmid < 0) { );
XDestroyImage(drv->image); if (Drv->xshm_info.shmid < 0) {
XDestroyImage(Drv->image);
return 0; return 0;
} }
drv->image_data = shmat (drv->xshm_info.shmid, NULL, 0); Drv->image_data = shmat (Drv->xshm_info.shmid, NULL, 0);
if(!drv->image_data) { if(!Drv->image_data) {
shmctl (drv->xshm_info.shmid, IPC_RMID, NULL); shmctl (Drv->xshm_info.shmid, IPC_RMID, NULL);
XDestroyImage(drv->image); XDestroyImage(Drv->image);
return 0; return 0;
} }
@ -140,16 +147,15 @@ TryCreateShmImage (
// This closes shared memory in real time on OS X. Only closes after folks quit using // This closes shared memory in real time on OS X. Only closes after folks quit using
// it on Linux. // it on Linux.
// //
/* Can this fail ? */ shmctl (Drv->xshm_info.shmid, IPC_RMID, NULL);
shmctl (drv->xshm_info.shmid, IPC_RMID, NULL);
#endif #endif
drv->xshm_info.shmaddr = (char*)drv->image_data; Drv->xshm_info.shmaddr = (char*)Drv->image_data;
drv->image->data = (char*)drv->image_data; Drv->image->data = (char*)Drv->image_data;
if (!XShmAttach (drv->display, &drv->xshm_info)) { if (!XShmAttach (Drv->display, &Drv->xshm_info)) {
shmdt (drv->image_data); shmdt (Drv->image_data);
XDestroyImage(drv->image); XDestroyImage(Drv->image);
return 0; return 0;
} }
return 1; return 1;
@ -163,69 +169,79 @@ X11Size(
IN UINT32 Height IN UINT32 Height
) )
{ {
GRAPHICS_IO_PRIVATE *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo; GRAPHICS_IO_PRIVATE *Drv;
XSizeHints size_hints; XSizeHints size_hints;
/* Destroy current buffer if created. */ // Destroy current buffer if created.
if (drv->image != NULL) Drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
{ if (Drv->image != NULL) {
/* Before destroy buffer, need to make sure the buffer available for access. */ // Before destroy buffer, need to make sure the buffer available for access.
XDestroyImage(drv->image); XDestroyImage (Drv->image);
if (drv->use_shm) if (Drv->use_shm) {
shmdt (drv->image_data); shmdt (Drv->image_data);
drv->image_data = NULL;
drv->image = NULL;
} }
drv->width = Width; Drv->image_data = NULL;
drv->height = Height; Drv->image = NULL;
XResizeWindow (drv->display, drv->win, Width, Height); }
/* Allocate image. */ Drv->width = Width;
if (XShmQueryExtension(drv->display) && TryCreateShmImage(drv)) { Drv->height = Height;
drv->use_shm = 1; XResizeWindow (Drv->display, Drv->win, Width, Height);
// Allocate image.
if (XShmQueryExtension(Drv->display) && TryCreateShmImage(Drv)) {
Drv->use_shm = 1;
} else { } else {
drv->use_shm = 0; Drv->use_shm = 0;
if (drv->depth > 16) if (Drv->depth > 16) {
drv->pixel_shift = 2; Drv->pixel_shift = 2;
else if (drv->depth > 8) } else if (Drv->depth > 8) {
drv->pixel_shift = 1; Drv->pixel_shift = 1;
else } else {
drv->pixel_shift = 0; Drv->pixel_shift = 0;
drv->image_data = malloc((drv->width * drv->height) << drv->pixel_shift);
drv->image = XCreateImage (drv->display, drv->visual, drv->depth,
ZPixmap, 0, (char *)drv->image_data,
drv->width, drv->height,
8 << drv->pixel_shift, 0);
} }
drv->line_bytes = drv->image->bytes_per_line;
fill_shift_mask (&drv->r, drv->image->red_mask);
fill_shift_mask (&drv->g, drv->image->green_mask);
fill_shift_mask (&drv->b, drv->image->blue_mask);
/* Set WM hints. */ Drv->image_data = malloc ((Drv->width * Drv->height) << Drv->pixel_shift);
Drv->image = XCreateImage (
Drv->display, Drv->visual, Drv->depth,
ZPixmap, 0, (char *)Drv->image_data,
Drv->width, Drv->height,
8 << Drv->pixel_shift, 0
);
}
Drv->line_bytes = Drv->image->bytes_per_line;
fill_shift_mask (&Drv->r, Drv->image->red_mask);
fill_shift_mask (&Drv->g, Drv->image->green_mask);
fill_shift_mask (&Drv->b, Drv->image->blue_mask);
// Set WM hints.
size_hints.flags = PSize | PMinSize | PMaxSize; size_hints.flags = PSize | PMinSize | PMaxSize;
size_hints.min_width = size_hints.max_width = size_hints.base_width = Width; size_hints.min_width = size_hints.max_width = size_hints.base_width = Width;
size_hints.min_height = size_hints.max_height = size_hints.base_height = Height; size_hints.min_height = size_hints.max_height = size_hints.base_height = Height;
XSetWMNormalHints (drv->display, drv->win, &size_hints); XSetWMNormalHints (Drv->display, Drv->win, &size_hints);
XMapWindow (drv->display, drv->win); XMapWindow (Drv->display, Drv->win);
HandleEvents(drv); HandleEvents (Drv);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
void void
handleKeyEvent(GRAPHICS_IO_PRIVATE *drv, XEvent *ev, BOOLEAN Make) handleKeyEvent (
IN GRAPHICS_IO_PRIVATE *Drv,
IN XEvent *ev,
IN BOOLEAN Make
)
{ {
KeySym *KeySym; KeySym *KeySym;
EFI_KEY_DATA KeyData; EFI_KEY_DATA KeyData;
int KeySymArraySize; int KeySymArraySize;
if (Make) { if (Make) {
if (drv->key_count == NBR_KEYS) { if (Drv->key_count == NBR_KEYS) {
return; return;
} }
} }
@ -238,7 +254,7 @@ handleKeyEvent(GRAPHICS_IO_PRIVATE *drv, XEvent *ev, BOOLEAN Make)
// [2] and [3] are based on option and command modifiers. The problem we have is command V // [2] and [3] are based on option and command modifiers. The problem we have is command V
// could be mapped to a crazy Unicode character so the old scheme of returning a string. // could be mapped to a crazy Unicode character so the old scheme of returning a string.
// //
KeySym = XGetKeyboardMapping (drv->display, ev->xkey.keycode, 1, &KeySymArraySize); KeySym = XGetKeyboardMapping (Drv->display, ev->xkey.keycode, 1, &KeySymArraySize);
KeyData.Key.ScanCode = 0; KeyData.Key.ScanCode = 0;
KeyData.Key.UnicodeChar = 0; KeyData.Key.UnicodeChar = 0;
@ -248,10 +264,10 @@ handleKeyEvent(GRAPHICS_IO_PRIVATE *drv, XEvent *ev, BOOLEAN Make)
// Skipping EFI_SCROLL_LOCK_ACTIVE & EFI_NUM_LOCK_ACTIVE since they are not on Macs // Skipping EFI_SCROLL_LOCK_ACTIVE & EFI_NUM_LOCK_ACTIVE since they are not on Macs
// //
if ((ev->xkey.state & LockMask) == 0) { if ((ev->xkey.state & LockMask) == 0) {
drv->KeyState.KeyToggleState &= ~EFI_CAPS_LOCK_ACTIVE; Drv->KeyState.KeyToggleState &= ~EFI_CAPS_LOCK_ACTIVE;
} else { } else {
if (Make) { if (Make) {
drv->KeyState.KeyToggleState |= EFI_CAPS_LOCK_ACTIVE; Drv->KeyState.KeyToggleState |= EFI_CAPS_LOCK_ACTIVE;
} }
} }
@ -260,54 +276,54 @@ handleKeyEvent(GRAPHICS_IO_PRIVATE *drv, XEvent *ev, BOOLEAN Make)
switch (*KeySym) { switch (*KeySym) {
case XK_Control_R: case XK_Control_R:
if (Make) { if (Make) {
drv->KeyState.KeyShiftState |= EFI_RIGHT_CONTROL_PRESSED; Drv->KeyState.KeyShiftState |= EFI_RIGHT_CONTROL_PRESSED;
} else { } else {
drv->KeyState.KeyShiftState &= ~EFI_RIGHT_CONTROL_PRESSED; Drv->KeyState.KeyShiftState &= ~EFI_RIGHT_CONTROL_PRESSED;
} }
break; break;
case XK_Control_L: case XK_Control_L:
if (Make) { if (Make) {
drv->KeyState.KeyShiftState |= EFI_LEFT_CONTROL_PRESSED; Drv->KeyState.KeyShiftState |= EFI_LEFT_CONTROL_PRESSED;
} else { } else {
drv->KeyState.KeyShiftState &= ~EFI_LEFT_CONTROL_PRESSED; Drv->KeyState.KeyShiftState &= ~EFI_LEFT_CONTROL_PRESSED;
} }
break; break;
case XK_Shift_R: case XK_Shift_R:
if (Make) { if (Make) {
drv->KeyState.KeyShiftState |= EFI_RIGHT_SHIFT_PRESSED; Drv->KeyState.KeyShiftState |= EFI_RIGHT_SHIFT_PRESSED;
} else { } else {
drv->KeyState.KeyShiftState &= ~EFI_RIGHT_SHIFT_PRESSED; Drv->KeyState.KeyShiftState &= ~EFI_RIGHT_SHIFT_PRESSED;
} }
break; break;
case XK_Shift_L: case XK_Shift_L:
if (Make) { if (Make) {
drv->KeyState.KeyShiftState |= EFI_LEFT_SHIFT_PRESSED; Drv->KeyState.KeyShiftState |= EFI_LEFT_SHIFT_PRESSED;
} else { } else {
drv->KeyState.KeyShiftState &= ~EFI_LEFT_SHIFT_PRESSED; Drv->KeyState.KeyShiftState &= ~EFI_LEFT_SHIFT_PRESSED;
} }
break; break;
case XK_Mode_switch: case XK_Mode_switch:
if (Make) { if (Make) {
drv->KeyState.KeyShiftState |= EFI_LEFT_ALT_PRESSED; Drv->KeyState.KeyShiftState |= EFI_LEFT_ALT_PRESSED;
} else { } else {
drv->KeyState.KeyShiftState &= ~EFI_LEFT_ALT_PRESSED; Drv->KeyState.KeyShiftState &= ~EFI_LEFT_ALT_PRESSED;
} }
break; break;
case XK_Meta_R: case XK_Meta_R:
if (Make) { if (Make) {
drv->KeyState.KeyShiftState |= EFI_RIGHT_LOGO_PRESSED; Drv->KeyState.KeyShiftState |= EFI_RIGHT_LOGO_PRESSED;
} else { } else {
drv->KeyState.KeyShiftState &= ~EFI_RIGHT_LOGO_PRESSED; Drv->KeyState.KeyShiftState &= ~EFI_RIGHT_LOGO_PRESSED;
} }
break; break;
case XK_Meta_L: case XK_Meta_L:
if (Make) { if (Make) {
drv->KeyState.KeyShiftState |= EFI_LEFT_LOGO_PRESSED; Drv->KeyState.KeyShiftState |= EFI_LEFT_LOGO_PRESSED;
} else { } else {
drv->KeyState.KeyShiftState &= ~EFI_LEFT_LOGO_PRESSED; Drv->KeyState.KeyShiftState &= ~EFI_LEFT_LOGO_PRESSED;
} }
break; break;
@ -431,12 +447,12 @@ handleKeyEvent(GRAPHICS_IO_PRIVATE *drv, XEvent *ev, BOOLEAN Make)
} }
// The global state is our state // The global state is our state
KeyData.KeyState.KeyShiftState = drv->KeyState.KeyShiftState; KeyData.KeyState.KeyShiftState = Drv->KeyState.KeyShiftState;
KeyData.KeyState.KeyToggleState = drv->KeyState.KeyToggleState; KeyData.KeyState.KeyToggleState = Drv->KeyState.KeyToggleState;
if (*KeySym < XK_BackSpace) { if (*KeySym < XK_BackSpace) {
if (((drv->KeyState.KeyShiftState & (EFI_LEFT_SHIFT_PRESSED | EFI_RIGHT_SHIFT_PRESSED)) != 0) || if (((Drv->KeyState.KeyShiftState & (EFI_LEFT_SHIFT_PRESSED | EFI_RIGHT_SHIFT_PRESSED)) != 0) ||
((drv->KeyState.KeyToggleState & EFI_CAPS_LOCK_ACTIVE) != 0) ) { ((Drv->KeyState.KeyToggleState & EFI_CAPS_LOCK_ACTIVE) != 0) ) {
KeyData.Key.UnicodeChar = (CHAR16)KeySym[KEYSYM_UPPER]; KeyData.Key.UnicodeChar = (CHAR16)KeySym[KEYSYM_UPPER];
@ -451,101 +467,112 @@ handleKeyEvent(GRAPHICS_IO_PRIVATE *drv, XEvent *ev, BOOLEAN Make)
} }
if (Make) { if (Make) {
memcpy (&drv->keys[drv->key_wr], &KeyData, sizeof (EFI_KEY_DATA)); memcpy (&Drv->keys[Drv->key_wr], &KeyData, sizeof (EFI_KEY_DATA));
drv->key_wr = (drv->key_wr + 1) % NBR_KEYS; Drv->key_wr = (Drv->key_wr + 1) % NBR_KEYS;
drv->key_count++; Drv->key_count++;
if (drv->MakeRegisterdKeyCallback != NULL) { if (Drv->MakeRegisterdKeyCallback != NULL) {
ReverseGasketUint64Uint64 (drv->MakeRegisterdKeyCallback ,drv->RegisterdKeyCallbackContext, &KeyData); ReverseGasketUint64Uint64 (Drv->MakeRegisterdKeyCallback ,Drv->RegisterdKeyCallbackContext, &KeyData);
} }
} else { } else {
if (drv->BreakRegisterdKeyCallback != NULL) { if (Drv->BreakRegisterdKeyCallback != NULL) {
ReverseGasketUint64Uint64 (drv->BreakRegisterdKeyCallback ,drv->RegisterdKeyCallbackContext, &KeyData); ReverseGasketUint64Uint64 (Drv->BreakRegisterdKeyCallback ,Drv->RegisterdKeyCallbackContext, &KeyData);
} }
} }
} }
void void
handleMouseMoved(GRAPHICS_IO_PRIVATE *drv, XEvent *ev) handleMouseMoved(
IN GRAPHICS_IO_PRIVATE *Drv,
IN XEvent *ev
)
{ {
if ( ev->xmotion.x != drv->previous_x ) if (ev->xmotion.x != Drv->previous_x) {
{ Drv->pointer_state.RelativeMovementX += ( ev->xmotion.x - Drv->previous_x );
drv->pointer_state.RelativeMovementX += ( ev->xmotion.x - drv->previous_x ); Drv->previous_x = ev->xmotion.x;
drv->previous_x = ev->xmotion.x; Drv->pointer_state_changed = 1;
drv->pointer_state_changed = 1;
} }
if ( ev->xmotion.y != drv->previous_y ) if (ev->xmotion.y != Drv->previous_y) {
{ Drv->pointer_state.RelativeMovementY += ( ev->xmotion.y - Drv->previous_y );
drv->pointer_state.RelativeMovementY += ( ev->xmotion.y - drv->previous_y ); Drv->previous_y = ev->xmotion.y;
drv->previous_y = ev->xmotion.y; Drv->pointer_state_changed = 1;
drv->pointer_state_changed = 1;
} }
drv->pointer_state.RelativeMovementZ = 0; Drv->pointer_state.RelativeMovementZ = 0;
} }
void void
handleMouseDown(GRAPHICS_IO_PRIVATE *drv, XEvent *ev, BOOLEAN Pressed) handleMouseDown (
IN GRAPHICS_IO_PRIVATE *Drv,
IN XEvent *ev,
IN BOOLEAN Pressed
)
{ {
if ( ev->xbutton.button == Button1 ) if (ev->xbutton.button == Button1) {
{ Drv->pointer_state_changed = (Drv->pointer_state.LeftButton != Pressed);
drv->pointer_state_changed = ( drv->pointer_state.LeftButton != Pressed ); Drv->pointer_state.LeftButton = Pressed;
drv->pointer_state.LeftButton = Pressed;
} }
if ( ev->xbutton.button == Button2 ) if ( ev->xbutton.button == Button2 ) {
{ Drv->pointer_state_changed = (Drv->pointer_state.RightButton != Pressed);
drv->pointer_state_changed = ( drv->pointer_state.RightButton != Pressed ); Drv->pointer_state.RightButton = Pressed;
drv->pointer_state.RightButton = Pressed;
} }
} }
void void
Redraw(GRAPHICS_IO_PRIVATE *drv, UINTN X, UINTN Y, UINTN Width, UINTN Height) Redraw (
IN GRAPHICS_IO_PRIVATE *Drv,
IN UINTN X,
IN UINTN Y,
IN UINTN Width,
IN UINTN Height
)
{ {
if (drv->use_shm) if (Drv->use_shm) {
XShmPutImage (drv->display, drv->win, drv->gc, drv->image, XShmPutImage (
X, Y, X, Y, Width, Height, False); Drv->display, Drv->win, Drv->gc, Drv->image, X, Y, X, Y, Width, Height, False
else );
XPutImage (drv->display, drv->win, drv->gc, drv->image, } else {
X, Y, X, Y, Width, Height); XPutImage (
XFlush(drv->display); Drv->display, Drv->win, Drv->gc, Drv->image, X, Y, X, Y, Width, Height
);
}
XFlush(Drv->display);
} }
void void
HandleEvent(GRAPHICS_IO_PRIVATE *drv, XEvent *ev) HandleEvent(GRAPHICS_IO_PRIVATE *Drv, XEvent *ev)
{
switch (ev->type)
{ {
switch (ev->type) {
case Expose: case Expose:
Redraw(drv, ev->xexpose.x, ev->xexpose.y, Redraw (Drv, ev->xexpose.x, ev->xexpose.y,
ev->xexpose.width, ev->xexpose.height); ev->xexpose.width, ev->xexpose.height);
break; break;
case GraphicsExpose: case GraphicsExpose:
Redraw(drv, ev->xgraphicsexpose.x, ev->xgraphicsexpose.y, Redraw (Drv, ev->xgraphicsexpose.x, ev->xgraphicsexpose.y,
ev->xgraphicsexpose.width, ev->xgraphicsexpose.height); ev->xgraphicsexpose.width, ev->xgraphicsexpose.height);
break; break;
case KeyPress: case KeyPress:
handleKeyEvent(drv, ev, TRUE); handleKeyEvent (Drv, ev, TRUE);
break; break;
case KeyRelease: case KeyRelease:
handleKeyEvent(drv, ev, FALSE); handleKeyEvent (Drv, ev, FALSE);
break; break;
case MappingNotify: case MappingNotify:
XRefreshKeyboardMapping (&ev->xmapping); XRefreshKeyboardMapping (&ev->xmapping);
break; break;
case MotionNotify: case MotionNotify:
handleMouseMoved(drv, ev); handleMouseMoved (Drv, ev);
break; break;
case ButtonPress: case ButtonPress:
handleMouseDown(drv, ev, TRUE); handleMouseDown (Drv, ev, TRUE);
break; break;
case ButtonRelease: case ButtonRelease:
handleMouseDown(drv, ev, FALSE); handleMouseDown (Drv, ev, FALSE);
break; break;
#if 0 #if 0
case DestroyNotify: case DestroyNotify:
XCloseDisplay (drv->display); XCloseDisplay (Drv->display);
exit (1); exit (1);
break; break;
#endif #endif
@ -556,56 +583,76 @@ HandleEvent(GRAPHICS_IO_PRIVATE *drv, XEvent *ev)
} }
void void
HandleEvents(GRAPHICS_IO_PRIVATE *drv) HandleEvents (
{ IN GRAPHICS_IO_PRIVATE *Drv
while (XPending(drv->display) != 0) )
{ {
XEvent ev; XEvent ev;
XNextEvent (drv->display, &ev); while (XPending (Drv->display) != 0) {
HandleEvent(drv, &ev); XNextEvent (Drv->display, &ev);
HandleEvent (Drv, &ev);
} }
} }
unsigned long unsigned long
X11PixelToColor (GRAPHICS_IO_PRIVATE *drv, EFI_UGA_PIXEL pixel) X11PixelToColor (
IN GRAPHICS_IO_PRIVATE *Drv,
IN EFI_UGA_PIXEL pixel
)
{ {
return ((pixel.Red >> drv->r.csize) << drv->r.shift) return ((pixel.Red >> Drv->r.csize) << Drv->r.shift)
| ((pixel.Green >> drv->g.csize) << drv->g.shift) | ((pixel.Green >> Drv->g.csize) << Drv->g.shift)
| ((pixel.Blue >> drv->b.csize) << drv->b.shift); | ((pixel.Blue >> Drv->b.csize) << Drv->b.shift);
} }
EFI_UGA_PIXEL EFI_UGA_PIXEL
X11ColorToPixel (GRAPHICS_IO_PRIVATE *drv, unsigned long val) X11ColorToPixel (
IN GRAPHICS_IO_PRIVATE *Drv,
IN unsigned long val
)
{ {
EFI_UGA_PIXEL res; EFI_UGA_PIXEL Pixel;
memset (&res, 0, sizeof (EFI_UGA_PIXEL)); memset (&Pixel, 0, sizeof (EFI_UGA_PIXEL));
/* FIXME: should round instead of truncate. */
res.Red = (val >> drv->r.shift) << drv->r.csize;
res.Green = (val >> drv->g.shift) << drv->g.csize;
res.Blue = (val >> drv->b.shift) << drv->b.csize;
return res; // Truncation not an issue since X11 and EFI are both using 8 bits per color
Pixel.Red = (val >> Drv->r.shift) << Drv->r.csize;
Pixel.Green = (val >> Drv->g.shift) << Drv->g.csize;
Pixel.Blue = (val >> Drv->b.shift) << Drv->b.csize;
return Pixel;
} }
STATIC EFI_STATUS EFI_STATUS
CheckKeyInternal( GRAPHICS_IO_PRIVATE *drv, BOOLEAN delay ) CheckKeyInternal (
IN GRAPHICS_IO_PRIVATE *Drv,
IN BOOLEAN delay
)
{ {
HandleEvents(drv); HandleEvents (Drv);
if (drv->key_count != 0)
if (Drv->key_count != 0) {
return EFI_SUCCESS; return EFI_SUCCESS;
if ( delay ) }
/* EFI is polling. Be CPU-friendly. */
if (delay) {
// EFI is polling. Be CPU-friendly.
SecSleep (20); SecSleep (20);
}
return EFI_NOT_READY; return EFI_NOT_READY;
} }
EFI_STATUS EFI_STATUS
X11CheckKey(EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsIo) X11CheckKey (
IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsIo
)
{ {
GRAPHICS_IO_PRIVATE *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo; GRAPHICS_IO_PRIVATE *Drv;
return CheckKeyInternal(drv, TRUE);
Drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
return CheckKeyInternal (Drv, TRUE);
} }
EFI_STATUS EFI_STATUS
@ -615,16 +662,20 @@ X11GetKey (
IN EFI_KEY_DATA *KeyData IN EFI_KEY_DATA *KeyData
) )
{ {
GRAPHICS_IO_PRIVATE *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo; EFI_STATUS EfiStatus;
EFI_STATUS status; GRAPHICS_IO_PRIVATE *Drv;
status = CheckKeyInternal(drv, FALSE); Drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
if (status != EFI_SUCCESS)
return status; EfiStatus = CheckKeyInternal (Drv, FALSE);
if (EFI_ERROR (EfiStatus)) {
return EfiStatus;
}
CopyMem (KeyData, &Drv->keys[Drv->key_rd], sizeof (EFI_KEY_DATA));
Drv->key_rd = (Drv->key_rd + 1) % NBR_KEYS;
Drv->key_count--;
CopyMem (KeyData, &drv->keys[drv->key_rd], sizeof (EFI_KEY_DATA));
drv->key_rd = (drv->key_rd + 1) % NBR_KEYS;
drv->key_count--;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -636,11 +687,12 @@ X11KeySetState (
IN EFI_KEY_TOGGLE_STATE *KeyToggleState IN EFI_KEY_TOGGLE_STATE *KeyToggleState
) )
{ {
GRAPHICS_IO_PRIVATE *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo; GRAPHICS_IO_PRIVATE *Drv;
// XKeyEvent event;
Drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
if (*KeyToggleState & EFI_CAPS_LOCK_ACTIVE) { if (*KeyToggleState & EFI_CAPS_LOCK_ACTIVE) {
if ((drv->KeyState.KeyToggleState & EFI_CAPS_LOCK_ACTIVE) == 0) { if ((Drv->KeyState.KeyToggleState & EFI_CAPS_LOCK_ACTIVE) == 0) {
// //
// We could create an XKeyEvent and send a XK_Caps_Lock to // We could create an XKeyEvent and send a XK_Caps_Lock to
// the UGA/GOP Window // the UGA/GOP Window
@ -648,7 +700,7 @@ X11KeySetState (
} }
} }
drv->KeyState.KeyToggleState = *KeyToggleState; Drv->KeyState.KeyToggleState = *KeyToggleState;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -662,11 +714,13 @@ X11RegisterKeyNotify (
IN VOID *Context IN VOID *Context
) )
{ {
GRAPHICS_IO_PRIVATE *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo; GRAPHICS_IO_PRIVATE *Drv;
drv->MakeRegisterdKeyCallback = MakeCallBack; Drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
drv->BreakRegisterdKeyCallback = BreakCallBack;
drv->RegisterdKeyCallbackContext = Context; Drv->MakeRegisterdKeyCallback = MakeCallBack;
Drv->BreakRegisterdKeyCallback = BreakCallBack;
Drv->RegisterdKeyCallbackContext = Context;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -680,7 +734,7 @@ X11Blt (
IN EMU_GRAPHICS_WINDOWS__BLT_ARGS *Args IN EMU_GRAPHICS_WINDOWS__BLT_ARGS *Args
) )
{ {
GRAPHICS_IO_PRIVATE *Private = (GRAPHICS_IO_PRIVATE *)GraphicsIo; GRAPHICS_IO_PRIVATE *Private;
UINTN DstY; UINTN DstY;
UINTN SrcY; UINTN SrcY;
UINTN DstX; UINTN DstX;
@ -691,6 +745,10 @@ X11Blt (
UINT8 *Src; UINT8 *Src;
UINTN Nbr; UINTN Nbr;
unsigned long Color; unsigned long Color;
XEvent ev;
Private = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
// //
// Check bounds // Check bounds
@ -730,8 +788,7 @@ X11Blt (
Args->Delta -= Args->Width * sizeof (EFI_UGA_PIXEL); Args->Delta -= Args->Width * sizeof (EFI_UGA_PIXEL);
for (SrcY = Args->SourceY; SrcY < (Args->Height + Args->SourceY); SrcY++) { for (SrcY = Args->SourceY; SrcY < (Args->Height + Args->SourceY); SrcY++) {
for (SrcX = Args->SourceX; SrcX < (Args->Width + Args->SourceX); SrcX++) { for (SrcX = Args->SourceX; SrcX < (Args->Width + Args->SourceX); SrcX++) {
*Blt++ = X11ColorToPixel(Private, *Blt++ = X11ColorToPixel (Private, XGetPixel (Private->image, SrcX, SrcY));
XGetPixel(Private->image, SrcX, SrcY));
} }
Blt = (EFI_UGA_PIXEL *) ((UINT8 *) Blt + Args->Delta); Blt = (EFI_UGA_PIXEL *) ((UINT8 *) Blt + Args->Delta);
} }
@ -759,8 +816,7 @@ X11Blt (
Dst += Private->line_bytes; Dst += Private->line_bytes;
Src += Private->line_bytes; Src += Private->line_bytes;
} }
} } else {
else {
Dst += (Args->Height - 1) * Private->line_bytes; Dst += (Args->Height - 1) * Private->line_bytes;
Src += (Args->Height - 1) * Private->line_bytes; Src += (Args->Height - 1) * Private->line_bytes;
for (Index = 0; Index < Args->Height; Index++) { for (Index = 0; Index < Args->Height; Index++) {
@ -791,22 +847,27 @@ X11Blt (
// //
switch (BltOperation) { switch (BltOperation) {
case EfiUgaVideoToVideo: case EfiUgaVideoToVideo:
XCopyArea(Private->display, Private->win, Private->win, Private->gc, XCopyArea(
Args->SourceX, Args->SourceY, Args->Width, Args->Height, Args->DestinationX, Args->DestinationY); Private->display, Private->win, Private->win, Private->gc,
while (1) { Args->SourceX, Args->SourceY, Args->Width, Args->Height,
XEvent ev; Args->DestinationX, Args->DestinationY
);
while (1) {
XNextEvent (Private->display, &ev); XNextEvent (Private->display, &ev);
HandleEvent (Private, &ev); HandleEvent (Private, &ev);
if (ev.type == NoExpose || ev.type == GraphicsExpose) if (ev.type == NoExpose || ev.type == GraphicsExpose) {
break; break;
} }
}
break; break;
case EfiUgaVideoFill: case EfiUgaVideoFill:
Color = X11PixelToColor (Private, *BltBuffer); Color = X11PixelToColor (Private, *BltBuffer);
XSetForeground (Private->display, Private->gc, Color); XSetForeground (Private->display, Private->gc, Color);
XFillRectangle(Private->display, Private->win, Private->gc, XFillRectangle (
Args->DestinationX, Args->DestinationY, Args->Width, Args->Height); Private->display, Private->win, Private->gc,
Args->DestinationX, Args->DestinationY, Args->Width, Args->Height
);
XFlush (Private->display); XFlush (Private->display);
break; break;
case EfiUgaBltBufferToVideo: case EfiUgaBltBufferToVideo:
@ -818,41 +879,56 @@ X11Blt (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
STATIC EFI_STATUS EFI_STATUS
CheckPointerInternal( GRAPHICS_IO_PRIVATE *drv, BOOLEAN delay ) CheckPointerInternal (
IN GRAPHICS_IO_PRIVATE *Drv,
IN BOOLEAN delay
)
{ {
HandleEvents(drv); HandleEvents (Drv);
if (drv->pointer_state_changed != 0) if (Drv->pointer_state_changed != 0) {
return EFI_SUCCESS; return EFI_SUCCESS;
if ( delay ) }
/* EFI is polling. Be CPU-friendly. */
if ( delay ) {
// EFI is polling. Be CPU-friendly.
SecSleep (20); SecSleep (20);
}
return EFI_NOT_READY; return EFI_NOT_READY;
} }
EFI_STATUS EFI_STATUS
X11CheckPointer(EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsIo) X11CheckPointer (
IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsIo
)
{ {
GRAPHICS_IO_PRIVATE *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo; GRAPHICS_IO_PRIVATE *Drv;
return( CheckPointerInternal( drv, TRUE ) );
Drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
return CheckPointerInternal (Drv, TRUE);
} }
EFI_STATUS EFI_STATUS
X11GetPointerState (EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsIo, EFI_SIMPLE_POINTER_STATE *state) X11GetPointerState (EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsIo, EFI_SIMPLE_POINTER_STATE *state)
{ {
GRAPHICS_IO_PRIVATE *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo; EFI_STATUS EfiStatus;
EFI_STATUS status; GRAPHICS_IO_PRIVATE *Drv;
status = CheckPointerInternal( drv, FALSE ); Drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
if (status != EFI_SUCCESS)
return status;
memcpy( state, &drv->pointer_state, sizeof( EFI_SIMPLE_POINTER_STATE ) ); EfiStatus = CheckPointerInternal (Drv, FALSE);
if (EfiStatus != EFI_SUCCESS) {
return EfiStatus;
}
drv->pointer_state.RelativeMovementX = 0; memcpy (state, &Drv->pointer_state, sizeof (EFI_SIMPLE_POINTER_STATE));
drv->pointer_state.RelativeMovementY = 0;
drv->pointer_state.RelativeMovementZ = 0; Drv->pointer_state.RelativeMovementX = 0;
drv->pointer_state_changed = 0; Drv->pointer_state.RelativeMovementY = 0;
Drv->pointer_state.RelativeMovementZ = 0;
Drv->pointer_state_changed = 0;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -863,72 +939,66 @@ X11GraphicsWindowOpen (
IN EMU_IO_THUNK_PROTOCOL *This IN EMU_IO_THUNK_PROTOCOL *This
) )
{ {
GRAPHICS_IO_PRIVATE *drv; GRAPHICS_IO_PRIVATE *Drv;
unsigned int border_width = 0; unsigned int border_width = 0;
char *display_name = NULL; char *display_name = NULL;
int title_len;
drv = (GRAPHICS_IO_PRIVATE *)calloc (1, sizeof (GRAPHICS_IO_PRIVATE)); Drv = (GRAPHICS_IO_PRIVATE *)calloc (1, sizeof (GRAPHICS_IO_PRIVATE));
if (drv == NULL) if (Drv == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
}
drv->GraphicsIo.Size = GasketX11Size; Drv->GraphicsIo.Size = GasketX11Size;
drv->GraphicsIo.CheckKey = GasketX11CheckKey; Drv->GraphicsIo.CheckKey = GasketX11CheckKey;
drv->GraphicsIo.GetKey = GasketX11GetKey; Drv->GraphicsIo.GetKey = GasketX11GetKey;
drv->GraphicsIo.KeySetState = GasketX11KeySetState; Drv->GraphicsIo.KeySetState = GasketX11KeySetState;
drv->GraphicsIo.RegisterKeyNotify = GasketX11RegisterKeyNotify; Drv->GraphicsIo.RegisterKeyNotify = GasketX11RegisterKeyNotify;
drv->GraphicsIo.Blt = GasketX11Blt; Drv->GraphicsIo.Blt = GasketX11Blt;
drv->GraphicsIo.CheckPointer = GasketX11CheckPointer; Drv->GraphicsIo.CheckPointer = GasketX11CheckPointer;
drv->GraphicsIo.GetPointerState = GasketX11GetPointerState; Drv->GraphicsIo.GetPointerState = GasketX11GetPointerState;
drv->key_count = 0; Drv->key_count = 0;
drv->key_rd = 0; Drv->key_rd = 0;
drv->key_wr = 0; Drv->key_wr = 0;
drv->KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID; Drv->KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID;
drv->KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID; Drv->KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID;
drv->MakeRegisterdKeyCallback = NULL; Drv->MakeRegisterdKeyCallback = NULL;
drv->BreakRegisterdKeyCallback = NULL; Drv->BreakRegisterdKeyCallback = NULL;
drv->RegisterdKeyCallbackContext = NULL; Drv->RegisterdKeyCallbackContext = NULL;
drv->display = XOpenDisplay (display_name); Drv->display = XOpenDisplay (display_name);
if (drv->display == NULL) { if (Drv->display == NULL) {
fprintf (stderr, "uga: cannot connect to X server %s\n", XDisplayName (display_name)); fprintf (stderr, "uga: cannot connect to X server %s\n", XDisplayName (display_name));
free (drv); free (Drv);
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
drv->screen = DefaultScreen (drv->display); Drv->screen = DefaultScreen (Drv->display);
drv->visual = DefaultVisual (drv->display, drv->screen); Drv->visual = DefaultVisual (Drv->display, Drv->screen);
drv->win = XCreateSimpleWindow Drv->win = XCreateSimpleWindow (
(drv->display, RootWindow (drv->display, drv->screen), Drv->display, RootWindow (Drv->display, Drv->screen),
0, 0, 4, 4, border_width, 0, 0, 4, 4, border_width,
WhitePixel (drv->display, drv->screen), WhitePixel (Drv->display, Drv->screen),
BlackPixel (drv->display, drv->screen)); BlackPixel (Drv->display, Drv->screen)
);
drv->depth = DefaultDepth (drv->display, drv->screen); Drv->depth = DefaultDepth (Drv->display, Drv->screen);
XDefineCursor (drv->display, drv->win, XCreateFontCursor (drv->display, XC_pirate)); XDefineCursor (Drv->display, Drv->win, XCreateFontCursor (Drv->display, XC_pirate));
/* Compute title len and convert to Ascii. */ Drv->Title = malloc (StrSize (This->ConfigString));
for (title_len = 0; This->ConfigString[title_len] != 0; title_len++) UnicodeStrToAsciiStr (This->ConfigString, Drv->Title);
; XStoreName (Drv->display, Drv->win, Drv->Title);
{
char title[title_len + 1];
int i;
for (i = 0; i < title_len; i++)
title[i] = This->ConfigString[i];
title[i] = 0;
XStoreName (drv->display, drv->win, title); // XAutoRepeatOff (Drv->display);
} XSelectInput (
Drv->display, Drv->win,
ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask
);
Drv->gc = DefaultGC (Drv->display, Drv->screen);
// XAutoRepeatOff (drv->display); This->Private = (VOID *)Drv;
XSelectInput (drv->display, drv->win, This->Interface = (VOID *)Drv;
ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask );
drv->gc = DefaultGC (drv->display, drv->screen);
This->Private = (VOID *)drv;
This->Interface = (VOID *)drv;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -938,29 +1008,33 @@ X11GraphicsWindowClose (
IN EMU_IO_THUNK_PROTOCOL *This IN EMU_IO_THUNK_PROTOCOL *This
) )
{ {
GRAPHICS_IO_PRIVATE *drv = (GRAPHICS_IO_PRIVATE *)This->Private; GRAPHICS_IO_PRIVATE *Drv;
if (drv == NULL) Drv = (GRAPHICS_IO_PRIVATE *)This->Private;
if (Drv == NULL) {
return EFI_SUCCESS; return EFI_SUCCESS;
if (drv->image != NULL)
{
XDestroyImage(drv->image);
if (drv->use_shm)
shmdt (drv->image_data);
drv->image_data = NULL;
drv->image = NULL;
} }
XDestroyWindow(drv->display, drv->win);
XCloseDisplay(drv->display); if (Drv->image != NULL) {
XDestroyImage(Drv->image);
if (Drv->use_shm) {
shmdt (Drv->image_data);
}
Drv->image_data = NULL;
Drv->image = NULL;
}
XDestroyWindow (Drv->display, Drv->win);
XCloseDisplay (Drv->display);
#ifdef __APPLE__ #ifdef __APPLE__
// Free up the shared memory // Free up the shared memory
shmctl (drv->xshm_info.shmid, IPC_RMID, NULL); shmctl (Drv->xshm_info.shmid, IPC_RMID, NULL);
#endif #endif
free(drv); free (Drv);
return EFI_SUCCESS; return EFI_SUCCESS;
} }