Samuel Benson's patch from qemu-devel mailing list for updating Cocoa frontend to match new DisplayState code. Reportedly there are some issues with the patch under certain conditions but for the time being it's the best thing we have to get Cocoa frontend compiling and working.
int qemu_main(int argc, char **argv); // main defined in qemu/vl.c
NSWindow *normalWindow;
id cocoaView;
int qemu_main(int argc, char **argv); // main defined in qemu/vl.c
NSWindow *normalWindow;
id cocoaView;
-static void *screenBuffer;
+static DisplayChangeListener *dcl;
{
COCOA_DEBUG("QemuCocoaView: dealloc\n");
{
COCOA_DEBUG("QemuCocoaView: dealloc\n");
- if (screenBuffer)
- free(screenBuffer);
-
if (dataProviderRef)
CGDataProviderRelease(dataProviderRef);
if (dataProviderRef)
CGDataProviderRelease(dataProviderRef);
{
COCOA_DEBUG("QemuCocoaView: drawRect\n");
{
COCOA_DEBUG("QemuCocoaView: drawRect\n");
- if ((int)screenBuffer == -1)
- return;
-
// get CoreGraphic context
CGContextRef viewContextRef = [[NSGraphicsContext currentContext] graphicsPort];
CGContextSetInterpolationQuality (viewContextRef, kCGInterpolationNone);
// get CoreGraphic context
CGContextRef viewContextRef = [[NSGraphicsContext currentContext] graphicsPort];
CGContextSetInterpolationQuality (viewContextRef, kCGInterpolationNone);
screen.height, //height
screen.bitsPerComponent, //bitsPerComponent
screen.bitsPerPixel, //bitsPerPixel
screen.height, //height
screen.bitsPerComponent, //bitsPerComponent
screen.bitsPerPixel, //bitsPerPixel
- (screen.width * 4), //bytesPerRow
+ (screen.width * (screen.bitsPerComponent/2)), //bytesPerRow
#if __LITTLE_ENDIAN__
CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB), //colorspace for OS X >= 10.4
#if __LITTLE_ENDIAN__
CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB), //colorspace for OS X >= 10.4
- kCGImageAlphaNoneSkipLast,
+ kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst,
#else
CGColorSpaceCreateDeviceRGB(), //colorspace for OS X < 10.4 (actually ppc)
kCGImageAlphaNoneSkipFirst, //bitmapInfo
#else
CGColorSpaceCreateDeviceRGB(), //colorspace for OS X < 10.4 (actually ppc)
kCGImageAlphaNoneSkipFirst, //bitmapInfo
// update screenBuffer
if (dataProviderRef)
CGDataProviderRelease(dataProviderRef);
// update screenBuffer
if (dataProviderRef)
CGDataProviderRelease(dataProviderRef);
- if (screenBuffer)
- free(screenBuffer);
- screenBuffer = malloc( w * 4 * h );
-
- ds->data = screenBuffer;
- ds->linesize = (w * 4);
- ds->depth = 32;
- ds->width = w;
- ds->height = h;
-#ifdef __LITTLE_ENDIAN__
- ds->bgr = 1;
-#else
- ds->bgr = 0;
-#endif
- dataProviderRef = CGDataProviderCreateWithData(NULL, screenBuffer, w * 4 * h, NULL);
+ //sync host window color space with guests
+ screen.bitsPerPixel = ds_get_bits_per_pixel(ds);
+ screen.bitsPerComponent = ds_get_bytes_per_pixel(ds) * 2;
+
+ dataProviderRef = CGDataProviderCreateWithData(NULL, ds_get_data(ds), w * 4 * h, NULL);
// update windows
if (isFullscreen) {
// update windows
if (isFullscreen) {
}
screen.width = w;
screen.height = h;
}
screen.width = w;
screen.height = h;
[self setContentDimensions];
[self setFrame:NSMakeRect(cx, cy, cw, ch)];
}
[self setContentDimensions];
[self setFrame:NSMakeRect(cx, cy, cw, ch)];
}
[normalWindow setTitle:[NSString stringWithFormat:@"QEMU"]];
[normalWindow setContentView:cocoaView];
[normalWindow makeKeyAndOrderFront:self];
[normalWindow setTitle:[NSString stringWithFormat:@"QEMU"]];
[normalWindow setContentView:cocoaView];
[normalWindow makeKeyAndOrderFront:self];
[cocoaView setNeedsDisplayInRect:rect];
}
[cocoaView setNeedsDisplayInRect:rect];
}
-static void cocoa_resize(DisplayState *ds, int w, int h)
+static void cocoa_resize(DisplayState *ds)
{
COCOA_DEBUG("qemu_cocoa: cocoa_resize\n");
{
COCOA_DEBUG("qemu_cocoa: cocoa_resize\n");
- [cocoaView resizeContentToWidth:w height:h displayState:ds];
+ [cocoaView resizeContentToWidth:(int)(ds_get_width(ds)) height:(int)(ds_get_height(ds)) displayState:ds];
}
static void cocoa_refresh(DisplayState *ds)
}
static void cocoa_refresh(DisplayState *ds)
static void cocoa_cleanup(void)
{
COCOA_DEBUG("qemu_cocoa: cocoa_cleanup\n");
static void cocoa_cleanup(void)
{
COCOA_DEBUG("qemu_cocoa: cocoa_cleanup\n");
}
void cocoa_display_init(DisplayState *ds, int full_screen)
{
COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n");
}
void cocoa_display_init(DisplayState *ds, int full_screen)
{
COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n");
- // register vga outpu callbacks
- ds->dpy_update = cocoa_update;
- ds->dpy_resize = cocoa_resize;
- ds->dpy_refresh = cocoa_refresh;
+ dcl = qemu_mallocz(sizeof(DisplayChangeListener));
+
+ // register vga output callbacks
+ dcl->dpy_update = cocoa_update;
+ dcl->dpy_resize = cocoa_resize;
+ dcl->dpy_refresh = cocoa_refresh;
- // give window a initial Size
- cocoa_resize(ds, 640, 400);
+ register_displaychangelistener(ds, dcl);
// register cleanup function
atexit(cocoa_cleanup);
// register cleanup function
atexit(cocoa_cleanup);