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) From: Programmingkid Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Mon, 5 Jan 2015 16:27:51 -0500 Message-Id: <3154DC97-3B67-4DBF-BD02-C64E4A9591E3@gmail.com> Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] Gives user ability to select endian format for video display - fixes Mac OS X guest color issue. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel qemu-devel Cc: Peter Maydell This patches does the following: - Allows user to select endian format of video display.=20 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=20 this feature.=20 - 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=20 version that was used to compile it. It also makes the code more efficient. Rather than setting the same variables over and over = again,=20 just do it once.=20 - 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; =20 +/* Used in drawRect:. Starts with little endian format. */ +static int bitmap_info =3D kCGBitmapByteOrder32Little | = kCGImageAlphaNoneSkipFirst; +SInt32 current_mac_os_version; + // keymap conversion int keymap[] =3D { @@ -238,7 +242,33 @@ static int cocoa_keycode_to_qemu(int keycode) return keymap[keycode]; } =20 +/* 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 =3D 0; i < argc; i++) { + if(strcmp(argv[i], "-display-endian-big") =3D=3D 0) { + bitmap_info =3D 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; + } + } +} =20 +/* Finds out what version of the Mac OS your computer is using. */ +static void determineMacOSVersion() +{ + OSErr err_num =3D Gestalt(gestaltSystemVersion, = ¤t_mac_os_version); + if(err_num !=3D noErr) { + current_mac_os_version =3D -1; + fprintf(stderr, "\nWarning: Failed to determine Mac OS version = of your system!\n"); + } +} =20 /* ------------------------------------------------------ @@ -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 =3D frameRect.size.width; screen.height =3D frameRect.size.height; [self updateWindowModeSettings]; + + if (current_mac_os_version >=3D MAC_OS_X_VERSION_10_4) + color_space =3D = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); + else { + /* Using this in Mac OS 10.6 causes occasional crashes in = drawRect:. */ + color_space =3D 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 >=3D 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; =20 self =3D [super init]; if (self) { + determineMacOSVersion(); =20 // create a view and add it to the window cocoaView =3D [[QemuCocoaView alloc] = initWithFrame:NSMakeRect(0.0, 0.0, 640.0, 480.0)]; @@ -918,6 +952,7 @@ QemuCocoaView *cocoaView; COCOA_DEBUG("QemuCocoaAppController: startEmulationWithArgc\n"); =20 int status; + scanForDisplayEndianOption(argc, argv); status =3D qemu_main(argc, argv, *_NSGetEnviron()); exit(status); } --=20 1.7.5.4