qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v2] Gives user ability to select endian format for v


From: Programmingkid
Subject: [Qemu-devel] [PATCH v2] Gives user ability to select endian format for video display - fixes Mac OS X guest color issue.
Date: Fri, 9 Jan 2015 11:27:09 -0500

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 <address@hidden>

---
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;
 
+/* bitmap_info is 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,15 @@ static int cocoa_keycode_to_qemu(int keycode)
     return keymap[keycode];
 }
 
-
+/* Finds out what version of the Mac OS your computer is using. */
+static void determineMacOSVersion()
+{
+    OSErr err_num = Gestalt(gestaltSystemVersion, &current_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 +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 = 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 +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 >= 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;
 
     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)];
@@ -1072,16 +1088,13 @@ int main (int argc, const char * argv[]) {
     return 0;
 }
 
-
-
 #pragma mark qemu
 static void cocoa_update(DisplayChangeListener *dcl,
                          int x, int y, int w, int h)
 {
-    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
-
     COCOA_DEBUG("qemu_cocoa: cocoa_update\n");
-
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
     NSRect rect;
     rect = NSMakeRect(x, [cocoaView gscreen].height - y - h, w, h);
     [cocoaView setNeedsDisplayInRect:rect];
@@ -1094,6 +1107,12 @@ static void cocoa_switch(DisplayChangeListener *dcl,
     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
 
     COCOA_DEBUG("qemu_cocoa: cocoa_switch\n");
+
+    /* Determines the pixel format of the frame buffer */
+    if (surface->format == PIXMAN_b8g8r8x8) {
+        bitmap_info = kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipFirst;
+    }
+
     [cocoaView switchSurface:surface];
     [pool release];
 }
-- 
1.7.5.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]