From patchwork Mon Jan 5 21:27:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 425425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7656614009B for ; Tue, 6 Jan 2015 08:28:19 +1100 (AEDT) Received: from localhost ([::1]:34029 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8FCB-00030W-29 for incoming@patchwork.ozlabs.org; Mon, 05 Jan 2015 16:28:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8FBv-0002k6-8J for qemu-devel@nongnu.org; Mon, 05 Jan 2015 16:28:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y8FBr-0004uh-7D for qemu-devel@nongnu.org; Mon, 05 Jan 2015 16:27:59 -0500 Received: from mail-qg0-x22e.google.com ([2607:f8b0:400d:c04::22e]:52661) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8FBr-0004uE-26 for qemu-devel@nongnu.org; Mon, 05 Jan 2015 16:27:55 -0500 Received: by mail-qg0-f46.google.com with SMTP id q107so15809776qgd.33 for ; Mon, 05 Jan 2015 13:27:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:content-transfer-encoding:subject:date:message-id :cc:to:mime-version; bh=lv6merSe6feA0xDsBIAzitg7g7p2iwm4IszHprNZz3A=; b=Fq6H4VICxTMYqljM3JfUhVOjTAeo9vNmx09nrspiOTiDGuPtA81wPckA4G7Xbdhz0f fSe+i96VBs9u7mdFtJt9qp+KlsFnXuTDazflFfe7JAM1WP3m9EMC5bQ11YPn/4LTp3+T b9jaaT0Goe2GdL6M0p1oXGvA39Z+urZWXJfsjdyFfFA7V5cYSpsVcWN+D9p5azXSsFdF sLjy2YCrcMfZUqHyiQkT74ng/n1zYyY+uxbU7nLQBL1UYYI+Kyao17Cc7UeB7g9bZXHr wewCsvxDORYJ1JTBtPiGuttGmKpj4cppLKkfzyutXrsn1i863R/XgVLssTWAXi/ml5hr ubeg== X-Received: by 10.224.103.195 with SMTP id l3mr135398118qao.38.1420493274725; Mon, 05 Jan 2015 13:27:54 -0800 (PST) Received: from [192.168.0.2] (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by mx.google.com with ESMTPSA id c80sm10191629qge.5.2015.01.05.13.27.53 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 Jan 2015 13:27:53 -0800 (PST) From: Programmingkid Date: Mon, 5 Jan 2015 16:27:51 -0500 Message-Id: <3154DC97-3B67-4DBF-BD02-C64E4A9591E3@gmail.com> To: qemu-devel qemu-devel Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c04::22e Cc: Peter Maydell Subject: [Qemu-devel] Gives user ability to select endian format for video display - fixes Mac OS X guest color issue. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patches does the following: - Allows user to select endian format of video display. This allows Mac OS X to be used as a guest and show all its colors correctly. Just add -display-endian-big to the command line to use this feature. - Removes unneeded #ifdefs in drawRect: method. Correct method selection is done at runtime instead of compile time. This makes one binary work on more versions of Mac OS X rather than just the version that was used to compile it. It also makes the code more efficient. Rather than setting the same variables over and over again, just do it once. - Adds runtime identification code for determining which version of the Mac OS QEMU is running on. Signed-off-by: John Arbuckle --- ui/cocoa.m | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 42 insertions(+), 7 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 704d199..562fa29 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -64,6 +64,10 @@ static int last_buttons; int gArgc; char **gArgv; +/* Used in drawRect:. Starts with little endian format. */ +static int bitmap_info = kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst; +SInt32 current_mac_os_version; + // keymap conversion int keymap[] = { @@ -238,7 +242,33 @@ static int cocoa_keycode_to_qemu(int keycode) return keymap[keycode]; } +/* Looks for the -display-endian-big option being sent to QEMU. + Fixes the issue with the colors not being displayed correctly with Mac OS X as the host. + It is normally assumed that the frame buffer has data in the little endian format. + Mac OS X uses the big endian format. +*/ +static void scanForDisplayEndianOption(int argc, char * argv[]) +{ + // search for the -display-endian-big option + for(int i = 0; i < argc; i++) { + if(strcmp(argv[i], "-display-endian-big") == 0) { + bitmap_info = kCGImageAlphaNoneSkipFirst; + // remove the option from the argv array + sprintf(argv[i], "%s", "-no-frame"); // no-frame does nothing in cocoa, so it is harmless + break; + } + } +} +/* Finds out what version of the Mac OS your computer is using. */ +static void determineMacOSVersion() +{ + OSErr err_num = Gestalt(gestaltSystemVersion, ¤t_mac_os_version); + if(err_num != noErr) { + current_mac_os_version = -1; + fprintf(stderr, "\nWarning: Failed to determine Mac OS version of your system!\n"); + } +} /* ------------------------------------------------------ @@ -257,6 +287,7 @@ static int cocoa_keycode_to_qemu(int keycode) BOOL isAbsoluteEnabled; BOOL isMouseDeassociated; NSDictionary * window_mode_dict; /* keeps track of the guest' graphic settings */ + CGColorSpaceRef color_space; /* used in drawRect: */ } - (void) switchSurface:(DisplaySurface *)surface; - (void) grabMouse; @@ -299,6 +330,13 @@ QemuCocoaView *cocoaView; screen.width = frameRect.size.width; screen.height = frameRect.size.height; [self updateWindowModeSettings]; + + if (current_mac_os_version >= MAC_OS_X_VERSION_10_4) + color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); + else { + /* Using this in Mac OS 10.6 causes occasional crashes in drawRect:. */ + color_space = CGColorSpaceCreateDeviceRGB(); + } } return self; } @@ -361,13 +399,8 @@ QemuCocoaView *cocoaView; screen.bitsPerComponent, //bitsPerComponent screen.bitsPerPixel, //bitsPerPixel (screen.width * (screen.bitsPerComponent/2)), //bytesPerRow -#ifdef __LITTLE_ENDIAN__ - CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB), //colorspace for OS X >= 10.4 - kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst, -#else - CGColorSpaceCreateDeviceRGB(), //colorspace for OS X < 10.4 (actually ppc) - kCGImageAlphaNoneSkipFirst, //bitmapInfo -#endif + color_space, + bitmap_info, dataProviderRef, //provider NULL, //decode 0, //interpolate @@ -835,6 +868,7 @@ QemuCocoaView *cocoaView; self = [super init]; if (self) { + determineMacOSVersion(); // create a view and add it to the window cocoaView = [[QemuCocoaView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 640.0, 480.0)]; @@ -918,6 +952,7 @@ QemuCocoaView *cocoaView; COCOA_DEBUG("QemuCocoaAppController: startEmulationWithArgc\n"); int status; + scanForDisplayEndianOption(argc, argv); status = qemu_main(argc, argv, *_NSGetEnviron()); exit(status); }