Commit 9794f74f9c1dd0fbef30ded9e5c14c28a6fa579b

Authored by aliguori
1 parent e53bd703

Update cocoa.m to match new DisplayState code (Samuel Benson)

Version 2 does as follows:

[1]: Corrects endianness on issues by using native BGR to RGB conversion
[2]: Uses DisplayState accessors for obtaining graphics context information,
     which
[3]: Removes now unused variables, and
[4]: Allows reading of varying color modes (32bit/24/16), and converting to
     native colorspace
[5]: Attempts to keep itself centered on screen (as opposed to bottom right,
     which immediately goes off screen after bios load) on context changes
    (window resizes)

Testing working on i386 (gentoo, Windows 2000) and PPC (debian) guests on PPC
and x86 Macs.

In regards to [4], Windows 2000 displays fine on quick tests, but on the lowest
setting I could test, 16bit color depth at 4bpp, colors are slightly off. I
used gentoo install-x86-minimal-2008.0 in framebuffer mode to test above
setting; the usual grey text is now blue, and Tux appears to be BGR shifted. I
do not know if previous code worked at such a low color setting.

Signed-off-by: Samuel Benson <qemu_ml@digitalescape.info> 



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6683 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 20 additions and 33 deletions
@@ -57,7 +57,7 @@ typedef struct { @@ -57,7 +57,7 @@ typedef struct {
57 int qemu_main(int argc, char **argv); // main defined in qemu/vl.c 57 int qemu_main(int argc, char **argv); // main defined in qemu/vl.c
58 NSWindow *normalWindow; 58 NSWindow *normalWindow;
59 id cocoaView; 59 id cocoaView;
60 -static void *screenBuffer; 60 +static DisplayChangeListener *dcl;
61 61
62 int gArgc; 62 int gArgc;
63 char **gArgv; 63 char **gArgv;
@@ -292,9 +292,6 @@ int cocoa_keycode_to_qemu(int keycode) @@ -292,9 +292,6 @@ int cocoa_keycode_to_qemu(int keycode)
292 { 292 {
293 COCOA_DEBUG("QemuCocoaView: dealloc\n"); 293 COCOA_DEBUG("QemuCocoaView: dealloc\n");
294 294
295 - if (screenBuffer)  
296 - free(screenBuffer);  
297 -  
298 if (dataProviderRef) 295 if (dataProviderRef)
299 CGDataProviderRelease(dataProviderRef); 296 CGDataProviderRelease(dataProviderRef);
300 297
@@ -305,9 +302,6 @@ int cocoa_keycode_to_qemu(int keycode) @@ -305,9 +302,6 @@ int cocoa_keycode_to_qemu(int keycode)
305 { 302 {
306 COCOA_DEBUG("QemuCocoaView: drawRect\n"); 303 COCOA_DEBUG("QemuCocoaView: drawRect\n");
307 304
308 - if ((int)screenBuffer == -1)  
309 - return;  
310 -  
311 // get CoreGraphic context 305 // get CoreGraphic context
312 CGContextRef viewContextRef = [[NSGraphicsContext currentContext] graphicsPort]; 306 CGContextRef viewContextRef = [[NSGraphicsContext currentContext] graphicsPort];
313 CGContextSetInterpolationQuality (viewContextRef, kCGInterpolationNone); 307 CGContextSetInterpolationQuality (viewContextRef, kCGInterpolationNone);
@@ -320,10 +314,10 @@ int cocoa_keycode_to_qemu(int keycode) @@ -320,10 +314,10 @@ int cocoa_keycode_to_qemu(int keycode)
320 screen.height, //height 314 screen.height, //height
321 screen.bitsPerComponent, //bitsPerComponent 315 screen.bitsPerComponent, //bitsPerComponent
322 screen.bitsPerPixel, //bitsPerPixel 316 screen.bitsPerPixel, //bitsPerPixel
323 - (screen.width * 4), //bytesPerRow 317 + (screen.width * (screen.bitsPerComponent/2)), //bytesPerRow
324 #if __LITTLE_ENDIAN__ 318 #if __LITTLE_ENDIAN__
325 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB), //colorspace for OS X >= 10.4 319 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB), //colorspace for OS X >= 10.4
326 - kCGImageAlphaNoneSkipLast, 320 + kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst,
327 #else 321 #else
328 CGColorSpaceCreateDeviceRGB(), //colorspace for OS X < 10.4 (actually ppc) 322 CGColorSpaceCreateDeviceRGB(), //colorspace for OS X < 10.4 (actually ppc)
329 kCGImageAlphaNoneSkipFirst, //bitmapInfo 323 kCGImageAlphaNoneSkipFirst, //bitmapInfo
@@ -395,22 +389,12 @@ int cocoa_keycode_to_qemu(int keycode) @@ -395,22 +389,12 @@ int cocoa_keycode_to_qemu(int keycode)
395 // update screenBuffer 389 // update screenBuffer
396 if (dataProviderRef) 390 if (dataProviderRef)
397 CGDataProviderRelease(dataProviderRef); 391 CGDataProviderRelease(dataProviderRef);
398 - if (screenBuffer)  
399 - free(screenBuffer);  
400 - screenBuffer = malloc( w * 4 * h );  
401 -  
402 - ds->data = screenBuffer;  
403 - ds->linesize = (w * 4);  
404 - ds->depth = 32;  
405 - ds->width = w;  
406 - ds->height = h;  
407 -#ifdef __LITTLE_ENDIAN__  
408 - ds->bgr = 1;  
409 -#else  
410 - ds->bgr = 0;  
411 -#endif  
412 392
413 - dataProviderRef = CGDataProviderCreateWithData(NULL, screenBuffer, w * 4 * h, NULL); 393 + //sync host window color space with guests
  394 + screen.bitsPerPixel = ds_get_bits_per_pixel(ds);
  395 + screen.bitsPerComponent = ds_get_bytes_per_pixel(ds) * 2;
  396 +
  397 + dataProviderRef = CGDataProviderCreateWithData(NULL, ds_get_data(ds), w * 4 * h, NULL);
414 398
415 // update windows 399 // update windows
416 if (isFullscreen) { 400 if (isFullscreen) {
@@ -423,6 +407,7 @@ int cocoa_keycode_to_qemu(int keycode) @@ -423,6 +407,7 @@ int cocoa_keycode_to_qemu(int keycode)
423 } 407 }
424 screen.width = w; 408 screen.width = w;
425 screen.height = h; 409 screen.height = h;
  410 + [normalWindow center];
426 [self setContentDimensions]; 411 [self setContentDimensions];
427 [self setFrame:NSMakeRect(cx, cy, cw, ch)]; 412 [self setFrame:NSMakeRect(cx, cy, cw, ch)];
428 } 413 }
@@ -740,6 +725,7 @@ int cocoa_keycode_to_qemu(int keycode) @@ -740,6 +725,7 @@ int cocoa_keycode_to_qemu(int keycode)
740 [normalWindow setTitle:[NSString stringWithFormat:@"QEMU"]]; 725 [normalWindow setTitle:[NSString stringWithFormat:@"QEMU"]];
741 [normalWindow setContentView:cocoaView]; 726 [normalWindow setContentView:cocoaView];
742 [normalWindow makeKeyAndOrderFront:self]; 727 [normalWindow makeKeyAndOrderFront:self];
  728 + [normalWindow center];
743 729
744 } 730 }
745 return self; 731 return self;
@@ -939,11 +925,11 @@ static void cocoa_update(DisplayState *ds, int x, int y, int w, int h) @@ -939,11 +925,11 @@ static void cocoa_update(DisplayState *ds, int x, int y, int w, int h)
939 [cocoaView displayRect:rect]; 925 [cocoaView displayRect:rect];
940 } 926 }
941 927
942 -static void cocoa_resize(DisplayState *ds, int w, int h) 928 +static void cocoa_resize(DisplayState *ds)
943 { 929 {
944 COCOA_DEBUG("qemu_cocoa: cocoa_resize\n"); 930 COCOA_DEBUG("qemu_cocoa: cocoa_resize\n");
945 931
946 - [cocoaView resizeContentToWidth:w height:h displayState:ds]; 932 + [cocoaView resizeContentToWidth:(int)(ds_get_width(ds)) height:(int)(ds_get_height(ds)) displayState:ds];
947 } 933 }
948 934
949 static void cocoa_refresh(DisplayState *ds) 935 static void cocoa_refresh(DisplayState *ds)
@@ -975,20 +961,21 @@ static void cocoa_refresh(DisplayState *ds) @@ -975,20 +961,21 @@ static void cocoa_refresh(DisplayState *ds)
975 static void cocoa_cleanup(void) 961 static void cocoa_cleanup(void)
976 { 962 {
977 COCOA_DEBUG("qemu_cocoa: cocoa_cleanup\n"); 963 COCOA_DEBUG("qemu_cocoa: cocoa_cleanup\n");
978 - 964 + qemu_free(dcl);
979 } 965 }
980 966
981 void cocoa_display_init(DisplayState *ds, int full_screen) 967 void cocoa_display_init(DisplayState *ds, int full_screen)
982 { 968 {
983 COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n"); 969 COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n");
984 970
985 - // register vga outpu callbacks  
986 - ds->dpy_update = cocoa_update;  
987 - ds->dpy_resize = cocoa_resize;  
988 - ds->dpy_refresh = cocoa_refresh; 971 + dcl = qemu_mallocz(sizeof(DisplayChangeListener));
  972 +
  973 + // register vga output callbacks
  974 + dcl->dpy_update = cocoa_update;
  975 + dcl->dpy_resize = cocoa_resize;
  976 + dcl->dpy_refresh = cocoa_refresh;
989 977
990 - // give window a initial Size  
991 - cocoa_resize(ds, 640, 400); 978 + register_displaychangelistener(ds, dcl);
992 979
993 // register cleanup function 980 // register cleanup function
994 atexit(cocoa_cleanup); 981 atexit(cocoa_cleanup);