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 57 int qemu_main(int argc, char **argv); // main defined in qemu/vl.c
58 58 NSWindow *normalWindow;
59 59 id cocoaView;
60   -static void *screenBuffer;
  60 +static DisplayChangeListener *dcl;
61 61  
62 62 int gArgc;
63 63 char **gArgv;
... ... @@ -292,9 +292,6 @@ int cocoa_keycode_to_qemu(int keycode)
292 292 {
293 293 COCOA_DEBUG("QemuCocoaView: dealloc\n");
294 294  
295   - if (screenBuffer)
296   - free(screenBuffer);
297   -
298 295 if (dataProviderRef)
299 296 CGDataProviderRelease(dataProviderRef);
300 297  
... ... @@ -305,9 +302,6 @@ int cocoa_keycode_to_qemu(int keycode)
305 302 {
306 303 COCOA_DEBUG("QemuCocoaView: drawRect\n");
307 304  
308   - if ((int)screenBuffer == -1)
309   - return;
310   -
311 305 // get CoreGraphic context
312 306 CGContextRef viewContextRef = [[NSGraphicsContext currentContext] graphicsPort];
313 307 CGContextSetInterpolationQuality (viewContextRef, kCGInterpolationNone);
... ... @@ -320,10 +314,10 @@ int cocoa_keycode_to_qemu(int keycode)
320 314 screen.height, //height
321 315 screen.bitsPerComponent, //bitsPerComponent
322 316 screen.bitsPerPixel, //bitsPerPixel
323   - (screen.width * 4), //bytesPerRow
  317 + (screen.width * (screen.bitsPerComponent/2)), //bytesPerRow
324 318 #if __LITTLE_ENDIAN__
325 319 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB), //colorspace for OS X >= 10.4
326   - kCGImageAlphaNoneSkipLast,
  320 + kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst,
327 321 #else
328 322 CGColorSpaceCreateDeviceRGB(), //colorspace for OS X < 10.4 (actually ppc)
329 323 kCGImageAlphaNoneSkipFirst, //bitmapInfo
... ... @@ -395,22 +389,12 @@ int cocoa_keycode_to_qemu(int keycode)
395 389 // update screenBuffer
396 390 if (dataProviderRef)
397 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 399 // update windows
416 400 if (isFullscreen) {
... ... @@ -423,6 +407,7 @@ int cocoa_keycode_to_qemu(int keycode)
423 407 }
424 408 screen.width = w;
425 409 screen.height = h;
  410 + [normalWindow center];
426 411 [self setContentDimensions];
427 412 [self setFrame:NSMakeRect(cx, cy, cw, ch)];
428 413 }
... ... @@ -740,6 +725,7 @@ int cocoa_keycode_to_qemu(int keycode)
740 725 [normalWindow setTitle:[NSString stringWithFormat:@"QEMU"]];
741 726 [normalWindow setContentView:cocoaView];
742 727 [normalWindow makeKeyAndOrderFront:self];
  728 + [normalWindow center];
743 729  
744 730 }
745 731 return self;
... ... @@ -939,11 +925,11 @@ static void cocoa_update(DisplayState *ds, int x, int y, int w, int h)
939 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 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 935 static void cocoa_refresh(DisplayState *ds)
... ... @@ -975,20 +961,21 @@ static void cocoa_refresh(DisplayState *ds)
975 961 static void cocoa_cleanup(void)
976 962 {
977 963 COCOA_DEBUG("qemu_cocoa: cocoa_cleanup\n");
978   -
  964 + qemu_free(dcl);
979 965 }
980 966  
981 967 void cocoa_display_init(DisplayState *ds, int full_screen)
982 968 {
983 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 980 // register cleanup function
994 981 atexit(cocoa_cleanup);
... ...