ui/cocoa: Fix OSX 10.10 warnings (and drop 10.4 support)
cover ui/cocoa: Fix OSX 10.10 warnings (and drop 10.4 support)
This patchset fixes a number of new compile warnings when building on OSX10.10 which were not present on 10.9, which are mostly fixes to avoid deprecated APIs.
I've chosen to implement some of them by simply dropping the backward-compatibility support for OSX 10.4. This is basically a pragmatic decision since I don't think we can support ancient versions forever, especially when I don't actually have a system to test compiling them on. (Last time I tried building QEMU on 10.4 it was an insane pain because you had to start by building all the dependencies and a new compiler too.) I would not be terribly surprised somebody told me we'd already accidentally broken 10.4 compilation, in fact.
10.5 is the last PPC OSX release so it seems like a reasonable minimum-version requirement (though I don't have a 10.5 setup either, so am reliant on people telling me if it breaks.)
This patchset sits on top of my current cocoa.next branch which you can find here:
https://git.linaro.org/people/peter.maydell/qemu-arm.git cocoa.next
If you have a pre-10.10 system and can test that this patchset doesn't break compilation that would be nice. (I checked the Apple documentation's notes about when functions and constants were first defined, so it should be OK...)
Peter Maydell (6):
ui/cocoa: Drop tests for CGImageCreateWithImageInRect support ui/cocoa: Remove compatibility ifdefs for OSX 10.4 ui/cocoa: openPanelDidEnd returnCode should be NSInteger, not int ui/cocoa: Declare that QemuCocoaAppController implements
NSApplicationDelegate
ui/cocoa: Don't use NSWindow useOptimizedDrawing on OSX 10.10 and up ui/cocoa: Avoid deprecated NSOKButton/NSCancelButton constants
ui/cocoa.m | 87 ++++++++++++++++++++++++++------------------------------------ 1 file changed, 37 insertions(+), 50 deletions(-)
Signature · 1 line
2.2.1
PATCH 1/6 ui/cocoa: Drop tests for CGImageCreateWithImageInRect support
The code that tries to test at both compiletime and runtime for whether CGImageCreateWithImageInRect is supported provokes a compile warning on OSX 10.3:
ui/cocoa.m:378:13: warning: comparison of function 'CGImageCreateWithImageInRect'
equal to a null pointer is always false[-Wtautological-pointer-compare]
if (CGImageCreateWithImageInRect == NULL) { // test if "CGImageCreateWithImageInRect" is
supported on host at runtime
^~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~
The simplest way to deal with this is just to drop this code, since we don't in practice support OSX 10.4 anyway. (10.5 was released in 2007 and is the last PPC version, so is the earliest we really need to continue to support at all.)
--- ui/cocoa.m | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-)
ui/cocoa.m +20 -30
@@ -374,40 +374,30 @@ QemuCocoaView *cocoaView; 0, //interpolate kCGRenderingIntentDefault //intent ); -// 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 - // compatibility drawing code (draws everything) (OS X < 10.4) - CGContextDrawImage (viewContextRef, CGRectMake(0, 0, [self bounds].size.width, [self bounds].size.height), imageRef); -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) - } else { - // selective drawing code (draws only dirty rectangles) (OS X >= 10.4) - const NSRect *rectList; + // 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; + NSInteger rectCount; #else - int rectCount; + int rectCount; #endif - int i; - CGImageRef clipImageRef; - CGRect clipRect; - - [self getRectsBeingDrawn:&rectList count:&rectCount]; - for (i = 0; i < rectCount; i++) { - clipRect.origin.x = rectList[i].origin.x / cdx; - clipRect.origin.y = (float)screen.height - (rectList[i].origin.y + rectList[i].size.height) / cdy; - clipRect.size.width = rectList[i].size.width / cdx; - clipRect.size.height = rectList[i].size.height / cdy; - clipImageRef = CGImageCreateWithImageInRect( - imageRef, - clipRect - ); - CGContextDrawImage (viewContextRef, cgrect(rectList[i]), clipImageRef); - CGImageRelease (clipImageRef); - } + int i; + CGImageRef clipImageRef; + CGRect clipRect; + + [self getRectsBeingDrawn:&rectList count:&rectCount]; + for (i = 0; i < rectCount; i++) { + clipRect.origin.x = rectList[i].origin.x / cdx; + clipRect.origin.y = (float)screen.height - (rectList[i].origin.y + rectList[i].size.height) / cdy; + clipRect.size.width = rectList[i].size.width / cdx; + clipRect.size.height = rectList[i].size.height / cdy; + clipImageRef = CGImageCreateWithImageInRect( + imageRef, + clipRect + ); + CGContextDrawImage (viewContextRef, cgrect(rectList[i]), clipImageRef); + CGImageRelease (clipImageRef); } -#endif CGImageRelease (imageRef); } }
Signature · 1 line
2.2.1
PATCH 2/6 ui/cocoa: Remove compatibility ifdefs for OSX 10.4
In reply to Peter MaydellRemove compatibility ifdefs that work around OSX 10.4 not providing various typedefs and functions.
--- ui/cocoa.m | 17 ----------------- 1 file changed, 17 deletions(-)
ui/cocoa.m +0 -17
@@ -30,9 +30,6 @@ #include "ui/input.h" #include "sysemu/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
@@ -376,11 +373,7 @@ QemuCocoaView *cocoaView; ); // 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;
@@ -490,33 +483,25 @@ QemuCocoaView *cocoaView; isFullscreen = FALSE; [self ungrabMouse]; [self setContentDimensions]; -// 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 { -#endif [fullScreenWindow close]; [normalWindow setContentView: self]; [normalWindow makeKeyAndOrderFront: self]; [NSMenu setMenuBarVisible:YES]; -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) } -#endif } else { // switch from desktop to fullscreen isFullscreen = TRUE; [normalWindow orderOut: nil]; /* Hide the window */ [self grabMouse]; [self setContentDimensions]; -// 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, [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], kCGDisplayModeIsStretched, nil], NSFullScreenModeSetting, nil]]; } else { -#endif [NSMenu setMenuBarVisible:NO]; fullScreenWindow = [[NSWindow alloc] initWithContentRect:[[NSScreen mainScreen] frame] styleMask:NSBorderlessWindowMask
@@ -528,9 +513,7 @@ QemuCocoaView *cocoaView; [self setFrame:NSMakeRect(cx, cy, cw, ch)]; [[fullScreenWindow contentView] addSubview: self]; [fullScreenWindow makeKeyAndOrderFront:self]; -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) } -#endif } }
Signature · 1 line
2.2.1
PATCH 3/6 ui/cocoa: openPanelDidEnd returnCode should be NSInteger, not int
In reply to Peter MaydellThe type for openPanelDidEnd's returnCode argument should be NSInteger, not int. This only matters for the OSX 10.5 code path where we pass the method directly to an OSX function to call.
--- ui/cocoa.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ui/cocoa.m +2 -2
@@ -787,7 +787,7 @@ QemuCocoaView *cocoaView; { } - (void)startEmulationWithArgc:(int)argc argv:(char**)argv; -- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo; +- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo; - (void)doToggleFullScreen:(id)sender; - (void)toggleFullScreen:(id)sender; - (void)showQEMUDoc:(id)sender;
@@ -890,7 +890,7 @@ QemuCocoaView *cocoaView; exit(status); } -- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo +- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo { COCOA_DEBUG("QemuCocoaAppController: openPanelDidEnd\n");
Signature · 1 line
2.2.1
PATCH 4/6 ui/cocoa: Declare that QemuCocoaAppController implements NSApplicationDelegate
In reply to Peter MaydellOur class QemuCocoaAppController implements the NSApplicationDelegate interface, and we pass an object of this class to [NSApp setDelegate]. However, we weren't declaring in the class definition that we implemented this interface; in OSX 10.10 this provokes the following (slighly misleading) warning:
ui/cocoa.m:1031:24: warning: sending 'QemuCocoaAppController *' to parameter of
incompatible type 'id<NSFileManagerDelegate>'
[NSApp setDelegate:appController];
^~~~~~~~~~~~~
/System/Library/Frameworks/Foundation.framework/Headers/NSFileManager.h:109:47:
note: passing argument to parameter 'delegate' here
@property (assign) id <NSFileManagerDelegate> delegate NS_AVAILABLE(10_5,
2_0);
^Annoyingly, this interface wasn't formally defined until OSX 10.6, so we have to surround the relevant part of the @interface line with an ifdef.
--- ui/cocoa.m | 3 +++ 1 file changed, 3 insertions(+)
ui/cocoa.m +3 -0
@@ -784,6 +784,9 @@ QemuCocoaView *cocoaView; ------------------------------------------------------ */ @interface QemuCocoaAppController : NSObject +#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) + <NSApplicationDelegate> +#endif { } - (void)startEmulationWithArgc:(int)argc argv:(char**)argv;
Signature · 1 line
2.2.1
PATCH 5/6 ui/cocoa: Don't use NSWindow useOptimizedDrawing on OSX 10.10 and up
In reply to Peter MaydellStarting in OSX 10.10, NSWindow useOptimizedDrawing is deprecated, so don't use it there.
--- ui/cocoa.m | 5 +++++ 1 file changed, 5 insertions(+)
ui/cocoa.m +5 -0
@@ -36,6 +36,9 @@ #ifndef MAC_OS_X_VERSION_10_6 #define MAC_OS_X_VERSION_10_6 1060 #endif +#ifndef MAC_OS_X_VERSION_10_10 +#define MAC_OS_X_VERSION_10_10 101000 +#endif //#define DEBUG
@@ -824,7 +827,9 @@ QemuCocoaView *cocoaView; [normalWindow setAcceptsMouseMovedEvents:YES]; [normalWindow setTitle:[NSString stringWithFormat:@"QEMU"]]; [normalWindow setContentView:cocoaView]; +#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_10) [normalWindow useOptimizedDrawing:YES]; +#endif [normalWindow makeKeyAndOrderFront:self]; [normalWindow center]; stretch_video = false;
Signature · 1 line
2.2.1
PATCH 6/6 ui/cocoa: Avoid deprecated NSOKButton/NSCancelButton constants
In reply to Peter MaydellIn OSX 10.10, the NSOKButton and NSCancelButton constants are deprecated and provoke compiler warnings. Avoid them by using the NSFileHandlingPanelCancelButton and NSFileHandlingPanelOKButton constants instead. These are the documented correct constants for the 10.6-and-up beginSheetModalForWindow API we use. We also use the same method for the pre-10.6 compatibility code path, but conveniently the constant values are the same and the constant names have been present since 10.0. Preferring the constant names that match the non-legacy API makes more sense anyway.
--- ui/cocoa.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
ui/cocoa.m +8 -2
@@ -902,9 +902,15 @@ QemuCocoaView *cocoaView; { COCOA_DEBUG("QemuCocoaAppController: openPanelDidEnd\n"); - if(returnCode == NSCancelButton) { + /* The NSFileHandlingPanelOKButton/NSFileHandlingPanelCancelButton values for + * returnCode strictly only apply for the 10.6-and-up beginSheetModalForWindow + * API. For the legacy pre-10.6 beginSheetForDirectory API they are NSOKButton + * and NSCancelButton. However conveniently the values are the same. + * We use the non-legacy names because the others are deprecated in OSX 10.10. + */ + if (returnCode == NSFileHandlingPanelCancelButton) { exit(0); - } else if(returnCode == NSOKButton) { + } else if (returnCode == NSFileHandlingPanelOKButton) { char *img = (char*)[ [ [ sheet URL ] path ] cStringUsingEncoding:NSASCIIStringEncoding]; char **argv = g_new(char *, 4);
Signature · 1 line
2.2.1
Quoted 36 lines · Peter Maydell
This patchset fixes a number of new compile warnings when building on OSX10.10 which were not present on 10.9, which are mostly fixes to avoid deprecated APIs.
I've chosen to implement some of them by simply dropping the backward-compatibility support for OSX 10.4. This is basically a pragmatic decision since I don't think we can support ancient versions forever, especially when I don't actually have a system to test compiling them on. (Last time I tried building QEMU on 10.4 it was an insane pain because you had to start by building all the dependencies and a new compiler too.) I would not be terribly surprised somebody told me we'd already accidentally broken 10.4 compilation, in fact.
10.5 is the last PPC OSX release so it seems like a reasonable minimum-version requirement (though I don't have a 10.5 setup either, so am reliant on people telling me if it breaks.)
This patchset sits on top of my current cocoa.next branch which you can find here:
https://git.linaro.org/people/peter.maydell/qemu-arm.git cocoa.nextIf you have a pre-10.10 system and can test that this patchset doesn't break compilation that would be nice. (I checked the Apple documentation's notes about when functions and constants were first defined, so it should be OK...)
Peter Maydell (6):
ui/cocoa: Drop tests for CGImageCreateWithImageInRect support ui/cocoa: Remove compatibility ifdefs for OSX 10.4 ui/cocoa: openPanelDidEnd returnCode should be NSInteger, not int ui/cocoa: Declare that QemuCocoaAppController implements
NSApplicationDelegate
ui/cocoa: Don't use NSWindow useOptimizedDrawing on OSX 10.10 and up ui/cocoa: Avoid deprecated NSOKButton/NSCancelButton constants
Quoted 6 lines
ui/cocoa.m | 87 ++++++++++++++++++++++++++------------------------------------
1 file changed, 37 insertions(+), 50 deletions(-)Signature · 1 line
2.2.1
I hate seeing support for older operating system end. The only thing you appear to be seeing are warnings. Are they really so bad? It might be simpler to just disable warnings. In the end I guess there isn't someone out there who is using QEMU on Mac OS 10.4 or earlier.
Quoted 15 lines · Programmingkid
Quoted 10 lines · Peter Maydell
I've chosen to implement some of them by simply dropping the backward-compatibility support for OSX 10.4. This is basically a pragmatic decision since I don't think we can support ancient versions forever, especially when I don't actually have a system to test compiling them on. (Last time I tried building QEMU on 10.4 it was an insane pain because you had to start by building all the dependencies and a new compiler too.) I would not be terribly surprised somebody told me we'd already accidentally broken 10.4 compilation, in fact.
Quoted 3 lines
10.5 is the last PPC OSX release so it seems like a reasonable minimum-version requirement (though I don't have a 10.5 setup either, so am reliant on people telling me if it breaks.)
Quoted 5 lines
I hate seeing support for older operating system end. The only thing you appear to be seeing are warnings. Are they really so bad? It might be simpler to just disable warnings. In the end I guess there isn't someone out there who is using QEMU on Mac OS 10.4 or earlier.
Well, we've already in some sense dropped 10.4 support, because 10.4 doesn't have rez/setfile, so it won't build with the icon patch applied. I wouldn't mind continuing to support 10.4 if we had at least one person who had 10.4 and had an actual use for 10.4 support and regularly built on 10.4 and told us if we broke things. But we don't, so all that we're really doing with these ifdefs is making our code more complicated and harder to maintain. 10.5 came out in 2007...
-- PMM