Cocoa: ppc64 host support and various improvements
Hello,
Recently, OSX/ppc64 TCG support was merged. This series replaces the remainder of my ppc64 series, splitting it up for review and bisectability.
It starts with fixing an essential 64-bit incompatibility, followed by elimination of all cocoa.m warnings on a v10.5 ppc64 system.
Also included are respins of patches fixing errors/warnings on older hosts and optimizing drawing. Support for -nographic is added.
New is my modification of window close behavior plus another drawing optimization for non-overlapping Views.
Most of these patches do not depend on each other, so could be cherry-picked if necessary.
Also available at git://repo.or.cz/qemu/afaerber.git, branch cocoa.
Regards,
Andreas
PATCH 1/11 Cocoa: ppc64 host support
Fix integer usage in the Cocoa backend: NSInteger is long on LP64.
This makes the graphical display show up on a ppc64 host.
v3:
- Confine NSInteger to Mac OS X v10.5 and later
--- cocoa.m | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
cocoa.m +8 -0
@@ -28,6 +28,10 @@ #include "console.h" #include "sysemu.h" +#ifndef MAC_OS_X_VERSION_10_5 +#define MAC_OS_X_VERSION_10_5 1050 +#endif + //#define DEBUG
@@ -337,7 +341,11 @@ int cocoa_keycode_to_qemu(int keycode) } else { // selective drawing code (draws only dirty rectangles) (OS X >= 10.4) const NSRect *rectList; +#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) + NSInteger rectCount; +#else int rectCount; +#endif int i; CGImageRef clipImageRef; CGRect clipRect;
Signature · 1 line
1.6.5.3
PATCH 2/11 Cocoa: Silence warning for cocoa_keycode_to_qemu
Make cocoa_keycode_to_qemu static, to avoid:
warning: no previous prototype for ‘cocoa_keycode_to_qemu’
--- cocoa.m | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
cocoa.m +1 -1
@@ -233,7 +233,7 @@ int keymap[] = */ }; -int cocoa_keycode_to_qemu(int keycode) +static int cocoa_keycode_to_qemu(int keycode) { if((sizeof(keymap)/sizeof(int)) <= keycode) {
Signature · 1 line
1.6.5.3
PATCH 3/11 Cocoa: Silence warning on Big Endian host
__LITTLE_ENDIAN__ is undefined on Big Endian host.
--- cocoa.m | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
cocoa.m +1 -1
@@ -319,7 +319,7 @@ static int cocoa_keycode_to_qemu(int keycode) screen.bitsPerComponent, //bitsPerComponent screen.bitsPerPixel, //bitsPerPixel (screen.width * (screen.bitsPerComponent/2)), //bytesPerRow -#if __LITTLE_ENDIAN__ +#ifdef __LITTLE_ENDIAN__ CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB), //colorspace for OS X >= 10.4 kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst, #else
Signature · 1 line
1.6.5.3
PATCH 4/11 Cocoa: Silence type warning
Add const for "qemu" character literal, to avoid:
warning: initialization discards qualifiers from pointer target type
An earlier patch by John proposed to use char[5]. Since we do not modify the text and later copy it into malloc'ed memory, marking it as const seems sufficient.
--- cocoa.m | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
cocoa.m +1 -1
@@ -791,7 +791,7 @@ static int cocoa_keycode_to_qemu(int keycode) if(returnCode == NSCancelButton) { exit(0); } else if(returnCode == NSOKButton) { - char *bin = "qemu"; + const char *bin = "qemu"; char *img = (char*)[ [ sheet filename ] cStringUsingEncoding:NSASCIIStringEncoding]; char **argv = (char**)malloc( sizeof(char*)*3 );
Signature · 1 line
1.6.5.3
PATCH 5/11 Cocoa: Fix compilation on Mac OS X v10.4 and earlier
NSView's enterFullScreenMode:withOptions: and exitFullScreenModeWithOptions: are available on v10.5 and later only. Undefined methods raise warnings and undefined constants result in errors.
Reported by Ryan Schmidt.
While at it, avoid a warning on v10.3.9, where MAC_OS_X_VERSION_10_4 is not defined.
Spotted by John Arbuckle.
Fix associated comments.
--- cocoa.m | 17 ++++++++++------- 1 files changed, 10 insertions(+), 7 deletions(-)
cocoa.m +10 -7
@@ -28,6 +28,9 @@ #include "console.h" #include "sysemu.h" +#ifndef MAC_OS_X_VERSION_10_4 +#define MAC_OS_X_VERSION_10_4 1040 +#endif #ifndef MAC_OS_X_VERSION_10_5 #define MAC_OS_X_VERSION_10_5 1050 #endif
@@ -331,7 +334,7 @@ static int cocoa_keycode_to_qemu(int keycode) 0, //interpolate kCGRenderingIntentDefault //intent ); -// test if host support "CGImageCreateWithImageInRect" at compiletime +// test if host supports "CGImageCreateWithImageInRect" at compile time #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) if (CGImageCreateWithImageInRect == NULL) { // test if "CGImageCreateWithImageInRect" is supported on host at runtime #endif
@@ -428,8 +431,8 @@ static int cocoa_keycode_to_qemu(int keycode) isFullscreen = FALSE; [self ungrabMouse]; [self setContentDimensions]; -// test if host support "enterFullScreenMode:withOptions" at compiletime -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) +// test if host supports "exitFullScreenModeWithOptions" at compile time +#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if ([NSView respondsToSelector:@selector(exitFullScreenModeWithOptions:)]) { // test if "exitFullScreenModeWithOptions" is supported on host at runtime [self exitFullScreenModeWithOptions:nil]; } else {
@@ -438,15 +441,15 @@ static int cocoa_keycode_to_qemu(int keycode) [normalWindow setContentView: self]; [normalWindow makeKeyAndOrderFront: self]; [NSMenu setMenuBarVisible:YES]; -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) +#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) } #endif } else { // switch from desktop to fullscreen isFullscreen = TRUE; [self grabMouse]; [self setContentDimensions]; -// test if host support "enterFullScreenMode:withOptions" at compiletime -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) +// test if host supports "enterFullScreenMode:withOptions" at compile time +#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if ([NSView respondsToSelector:@selector(enterFullScreenMode:withOptions:)]) { // test if "enterFullScreenMode:withOptions" is supported on host at runtime [self enterFullScreenMode:[NSScreen mainScreen] withOptions:[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:NO], NSFullScreenModeAllScreens,
@@ -462,7 +465,7 @@ static int cocoa_keycode_to_qemu(int keycode) [fullScreenWindow setHasShadow:NO]; [fullScreenWindow setContentView:self]; [fullScreenWindow makeKeyAndOrderFront:self]; -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) +#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) } #endif }
Signature · 1 line
1.6.5.3
PATCH 6/11 Cocoa: Mark the View as opaque
Default is NO.
Based on patch by Juha Riihimäki.
--- cocoa.m | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
cocoa.m +5 -0
@@ -305,6 +305,11 @@ static int cocoa_keycode_to_qemu(int keycode) [super dealloc]; } +- (BOOL) isOpaque +{ + return YES; +} + - (void) drawRect:(NSRect) rect { COCOA_DEBUG("QemuCocoaView: drawRect\n");
Signature · 1 line
1.6.5.3
PATCH 7/11 Cocoa: Redraw the View asynchronously
Based on patch by Juha Riihimäki.
--- cocoa.m | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
cocoa.m +1 -1
@@ -938,7 +938,7 @@ static void cocoa_update(DisplayState *ds, int x, int y, int w, int h) w * [cocoaView cdx], h * [cocoaView cdy]); } - [cocoaView displayRect:rect]; + [cocoaView setNeedsDisplayInRect:rect]; } static void cocoa_resize(DisplayState *ds)
Signature · 1 line
1.6.5.3
PATCH 8/11 Cocoa: Don't unconditionally show the window
When QEMU was launched in no-graphic, Curses or VNC mode, don't run it as a Cocoa application.
Based on patch by Alexander Graf.
v1:
- Avoid type mismatch warning for argv
- Drop noCocoa variable
- Coding Style changes
--- cocoa.m | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
cocoa.m +10 -0
@@ -855,6 +855,16 @@ int main (int argc, const char * argv[]) { gArgc = argc; gArgv = (char **)argv; CPSProcessSerNum PSN; + int i; + + /* In case we don't need to display a window, let's not do that */ + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-vnc") || + !strcmp(argv[i], "-nographic") || + !strcmp(argv[i], "-curses")) { + return qemu_main(gArgc, gArgv); + } + } NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; [NSApplication sharedApplication];
Signature · 1 line
1.6.5.3
PATCH 9/11 Cocoa: Shutdown when window is closed
The application is not very useful once the guest window is closed. QEMU is not a document-based application; terminating it automatically saves the user another action and resembles SDL behavior.
--- cocoa.m | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
cocoa.m +7 -0
@@ -712,6 +712,7 @@ static int cocoa_keycode_to_qemu(int keycode) - (void)toggleFullScreen:(id)sender; - (void)showQEMUDoc:(id)sender; - (void)showQEMUTec:(id)sender; +- (void)windowWillClose:(NSNotification *)notification; @end @implementation QemuCocoaAppController
@@ -737,6 +738,7 @@ static int cocoa_keycode_to_qemu(int keycode) fprintf(stderr, "(cocoa) can't create window\n"); exit(1); } + [normalWindow setDelegate:self]; [normalWindow setAcceptsMouseMovedEvents:YES]; [normalWindow setTitle:[NSString stringWithFormat:@"QEMU"]]; [normalWindow setContentView:cocoaView];
@@ -835,6 +837,11 @@ static int cocoa_keycode_to_qemu(int keycode) [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-tech.html", [[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"]; } + +- (void)windowWillClose:(NSNotification *)notification +{ + [NSApp terminate:self]; +} @end
Signature · 1 line
1.6.5.3
PATCH 10/11 Cocoa: Suppress window resize animation
Disable the nice resize animation, to avoid drawing glitches following a guest's screen size change.
Based on patch by Juha Riihimäki.
--- cocoa.m | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
cocoa.m +1 -1
@@ -419,7 +419,7 @@ static int cocoa_keycode_to_qemu(int keycode) } else { if (qemu_name) [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s", qemu_name]]; - [normalWindow setFrame:NSMakeRect([normalWindow frame].origin.x, [normalWindow frame].origin.y - h + screen.height, w, h + [normalWindow frame].size.height - screen.height) display:YES animate:YES]; + [normalWindow setFrame:NSMakeRect([normalWindow frame].origin.x, [normalWindow frame].origin.y - h + screen.height, w, h + [normalWindow frame].size.height - screen.height) display:YES animate:NO]; } screen.width = w; screen.height = h;
Signature · 1 line
1.6.5.3
PATCH 11/11 Cocoa: Use optimized drawing for the window
Default is NO.
--- cocoa.m | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
cocoa.m +1 -0
@@ -742,6 +742,7 @@ static int cocoa_keycode_to_qemu(int keycode) [normalWindow setAcceptsMouseMovedEvents:YES]; [normalWindow setTitle:[NSString stringWithFormat:@"QEMU"]]; [normalWindow setContentView:cocoaView]; + [normalWindow useOptimizedDrawing:YES]; [normalWindow makeKeyAndOrderFront:self]; [normalWindow center];
Signature · 1 line
1.6.5.3
Re: [Qemu-devel] [PATCH 09/11] Cocoa: Shutdown when window is closed
In reply to Andreas FärberQuoted 40 lines · ext Andreas Färber
The application is not very useful once the guest window is closed. QEMU is not a document-based application; terminating it automatically saves the user another action and resembles SDL behavior.
Signed-off-by Andreas Färber <[email protected]>Cc Mike Kronenberg <[email protected]>Cc Alexander Graf <[email protected]>---
cocoa.m | 7 +++++++1 files changed, 7 insertions(+), 0 deletions(-)cocoa.m +1
-3@@ -712,6 +712,7 @@ static int cocoa_keycode_to_qemu(int keycode) - (void)toggleFullScreen:(id)sender; - (void)showQEMUDoc:(id)sender; - (void)showQEMUTec:(id)sender; +- (void)windowWillClose:(NSNotification *)notification;@end
@implementation QemuCocoaAppController
cocoa.m +6
-0@@ -737,6 +738,7 @@ static int cocoa_keycode_to_qemu(int keycode) fprintf(stderr, "(cocoa) can't create window\n"); exit(1); } + [normalWindow setDelegate:self]; [normalWindow setAcceptsMouseMovedEvents:YES]; [normalWindow setTitle:[NSString stringWithFormat:@"QEMU"]]; [normalWindow setContentView:cocoaView];@@ -835,6 +837,11 @@ static int cocoa_keycode_to_qemu(int keycode) [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-tech.html", [[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"]; } + +- (void)windowWillClose:(NSNotification *)notification +{ + [NSApp terminate:self]; +}
Quoted 2 lines
@end
Another way to achieve the same thing is to instead of the above changes just introduce a new method for the QemuCocoaAppController like:
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
{
return YES;
}Regards,
Juha
PATCH v2 9/11 Cocoa: Shutdown when window is closed
The application is not very useful once the guest window is closed. QEMU is not a document-based application; terminating it automatically saves the user another action and resembles SDL behavior.
v2:
- Use delegate method, suggested by Juha Riihimäki.
--- cocoa.m | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
cocoa.m +5 -0
@@ -783,6 +783,11 @@ static int cocoa_keycode_to_qemu(int keycode) exit(0); } +- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication +{ + return YES; +} + - (void)startEmulationWithArgc:(int)argc argv:(char**)argv { COCOA_DEBUG("QemuCocoaAppController: startEmulationWithArgc\n");
Signature · 1 line
1.6.5.3
Re: [Qemu-devel] [PATCH 09/11] Cocoa: Shutdown when window is closed
In reply to [email protected]Hi,
Am 14.12.2009 um 08:04 schrieb <[email protected]> <[email protected]>:
Quoted 35 lines · ext Andreas Färber
Quoted 28 lines
The application is not very useful once the guest window is closed. QEMU is not a document-based application; terminating it automatically saves the user another action and resembles SDL behavior.
Signed-off-by Andreas Färber <[email protected]>Cc Mike Kronenberg <[email protected]>Cc Alexander Graf <[email protected]>---
cocoa.m | 7 +++++++1 files changed, 7 insertions(+), 0 deletions(-)cocoa.m +5
-0@@ -835,6 +837,11 @@ static int cocoa_keycode_to_qemu(int keycode) [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-tech.html", [[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"]; } + +- (void)windowWillClose:(NSNotification *)notification +{ + [NSApp terminate:self]; +}Quoted 2 lines
@end
Another way to achieve the same thing is to instead of the above changes just introduce a new method for the QemuCocoaAppController like:
Quoted 5 lines
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:
(NSApplication *)theApplication{ return YES; }
That's ingenious. I had searched for something like this, but around NSWindow... thanks!
Any other comments? Would you like to add an SoB to the now four patches proposed by you?
Regards,
Andreas