Revision 9794f74f cocoa.m
b/cocoa.m | ||
---|---|---|
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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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); |
Also available in: Unified diff