diff --git a/src/macosx/MacMiniFB.m b/src/macosx/MacMiniFB.m index 2998027..432ebd2 100644 --- a/src/macosx/MacMiniFB.m +++ b/src/macosx/MacMiniFB.m @@ -40,8 +40,7 @@ create_window_data(unsigned width, unsigned height) { window_data->specific = window_data_osx; - window_data->dst_width = width; - window_data->dst_height = height; + calc_dst_factor(window_data, width, height); window_data->buffer_width = width; window_data->buffer_height = height; @@ -366,6 +365,7 @@ mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y window_data->dst_offset_y = offset_y; window_data->dst_width = width; window_data->dst_height = height; + calc_dst_factor(window_data, window_data->window_width, window_data->window_height); #if defined(USE_METAL_API) float x1 = ((float) offset_x / window_data->window_width) * 2.0f - 1.0f; diff --git a/src/macosx/OSXView.m b/src/macosx/OSXView.m index c9a0185..1e63206 100644 --- a/src/macosx/OSXView.m +++ b/src/macosx/OSXView.m @@ -52,13 +52,27 @@ if (!window_data_osx || !window_data_osx->window || !window_data->draw_buffer) return; - CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; + CGContextRef context = [[NSGraphicsContext currentContext] CGContext]; CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); - CGDataProviderRef provider = CGDataProviderCreateWithData(0x0, window_data->draw_buffer, window_data->buffer_width * window_data->buffer_height * 4, 0x0); + CGDataProviderRef provider = CGDataProviderCreateWithData(0x0, + window_data->draw_buffer, + window_data->buffer_width * window_data->buffer_height * 4, + 0x0 + ); - CGImageRef img = CGImageCreate(window_data->buffer_width, window_data->buffer_height, 8, 32, window_data->buffer_width * 4, space, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, - provider, 0x0, false, kCGRenderingIntentDefault); + CGImageRef img = CGImageCreate(window_data->buffer_width + , window_data->buffer_height + , 8 + , 32 + , window_data->buffer_width * 4 + , space + , kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little + , provider + , 0x0 + , false + , kCGRenderingIntentDefault + ); const CGFloat components[] = {0.0f, 0.0f, 0.0f, 1.0f}; const CGColorRef black = CGColorCreate(space, components); @@ -68,10 +82,14 @@ if(window_data->dst_offset_x != 0 || window_data->dst_offset_y != 0 || window_data->dst_width != window_data->window_width || window_data->dst_height != window_data->window_height) { CGContextSetFillColorWithColor(context, black); - CGContextFillRect(context, CGRectMake(0, 0, window_data->window_width, window_data->window_height)); + CGContextFillRect(context, rect); } - CGContextDrawImage(context, CGRectMake(window_data->dst_offset_x, window_data->dst_offset_y, window_data->dst_width, window_data->dst_height), img); + // TODO: Sometimes there is a crash here + CGContextDrawImage(context, + CGRectMake(window_data->dst_offset_x, window_data->dst_offset_y, window_data->dst_width, window_data->dst_height), + img + ); CGImageRelease(img); }