Received: from eggs.gnu.org ([2001:4830:134:3::10]:53771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9cP9-0002ik-7H for qemu-devel@nongnu.org; Fri, 09 Jan 2015 11:27:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y9cP4-0000bH-4U for qemu-devel@nongnu.org; Fri, 09 Jan 2015 11:27:19 -0500 Received: from mail-qg0-x229.google.com ([2607:f8b0:400d:c04::229]:39996) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9cP3-0000bD-V7 for qemu-devel@nongnu.org; Fri, 09 Jan 2015 11:27:14 -0500 Received: by mail-qg0-f41.google.com with SMTP id e89so9599414qgf.0 for ; Fri, 09 Jan 2015 08:27:13 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Programmingkid In-Reply-To: <1420793910.24278.6.camel@nilsson.home.kraxel.org> Date: Fri, 9 Jan 2015 11:27:09 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: <1F47539E-5ACE-4AFD-956B-266FAA04098D@gmail.com> References: <3154DC97-3B67-4DBF-BD02-C64E4A9591E3@gmail.com> <77FFD738-1433-4B15-8522-C1EA965B774B@gmail.com> <122C8E58-48F5-4A54-B0AF-A826492D73B6@gmail.com> <4A37A1CE-EE81-4408-A13E-8A4C7C91D498@gmail.com> <54AC45AE.5020804@redhat.com> <54AD0BDE.7020200@redhat.com> <1420641833.27381.39.camel@nilsson.home.kraxel.org> <67F5B5C0-41E1-4399-8A11-C3821394C31D@gmail.com> <1420707776.24470.15.camel@nilsson.home.kraxel.org> <07B03389-9719-42C2-A561-05347C36D947@gmail.com> <1420793910.24278.6.camel@nilsson.home.kraxel.org> Subject: [Qemu-devel] [PATCH v2] 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: Gerd Hoffmann Cc: Paolo Bonzini , qemu-devel qemu-devel , Peter Maydell This patch fixes the Mac OS X guest color problem on Mac OS X hosts. = Tested using Mac OS 10.2 and Debian Linux 5 operating systems for the = guest on qemu-system-ppc. Also tested using Windows XP as a guest in = qemu-system-i386. Signed-off-by: John Arbuckle --- v2: Eliminated the -display-endian-big command line switch and replaced = with code that automatically detects the correct pixel format. ui/cocoa.m | 45 ++++++++++++++++++++++++++++++++------------- 1 files changed, 32 insertions(+), 13 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 704d199..685081e 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -64,6 +64,10 @@ static int last_buttons; int gArgc; char **gArgv; =20 +/* bitmap_info is 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,15 @@ static int cocoa_keycode_to_qemu(int keycode) return keymap[keycode]; } =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 +269,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 +312,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 +381,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 +850,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)]; @@ -1072,16 +1088,13 @@ int main (int argc, const char * argv[]) { return 0; } =20 - - #pragma mark qemu static void cocoa_update(DisplayChangeListener *dcl, int x, int y, int w, int h) { - NSAutoreleasePool * pool =3D [[NSAutoreleasePool alloc] init]; - COCOA_DEBUG("qemu_cocoa: cocoa_update\n"); - + NSAutoreleasePool * pool =3D [[NSAutoreleasePool alloc] init]; + NSRect rect; rect =3D NSMakeRect(x, [cocoaView gscreen].height - y - h, w, h); [cocoaView setNeedsDisplayInRect:rect]; @@ -1094,6 +1107,12 @@ static void cocoa_switch(DisplayChangeListener = *dcl, NSAutoreleasePool * pool =3D [[NSAutoreleasePool alloc] init]; =20 COCOA_DEBUG("qemu_cocoa: cocoa_switch\n"); + + /* Determines the pixel format of the frame buffer */ + if (surface->format =3D=3D PIXMAN_b8g8r8x8) { + bitmap_info =3D kCGBitmapByteOrder32Big | = kCGImageAlphaNoneSkipFirst; + } + [cocoaView switchSurface:surface]; [pool release]; } --=20 1.7.5.4