summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-08-17 17:21:44 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-08-17 17:21:53 +0200
commitb8b280527041710b69e7dd18d721089698abb227 (patch)
tree673f2e554ab9cf34e19c33ed905396d3816e043e
parent5380706be71cb539789db88aea3d1f457e7b0698 (diff)
Make recent changes to support macOS 11.0 "Big Sur" active with 11.0 only.
An optimisation used for drawing to windows is not possible under 11.0. This commits reinstalls it under macOS 10.14 and 10.15.
-rw-r--r--src/Fl_cocoa.mm39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index d6da12bee..899f35d9b 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -559,7 +559,7 @@ void Fl_Cocoa_Screen_Driver::breakMacEventLoop()
#endif
- (BOOL)did_view_resolution_change;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
-- (void)create_aux_bitmap:(BOOL)retina;
+- (void)create_aux_bitmap:(CGContextRef)gc retina:(BOOL)r;
- (void)reset_aux_bitmap;
#endif
@end
@@ -2182,12 +2182,19 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
return NO;
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
-- (void)create_aux_bitmap:(BOOL)retina {
- int W = [self frame].size.width, H = [self frame].size.height;
- if (retina) { W *= 2; H *= 2; }
- static CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
- aux_bitmap = CGBitmapContextCreate(NULL, W, H, 8, 0, cspace, kCGImageAlphaPremultipliedFirst);
- if (retina) CGContextScaleCTM(aux_bitmap, 2, 2);
+- (void)create_aux_bitmap:(CGContextRef)gc retina:(BOOL)r {
+ if (!gc || fl_mac_os_version >= 110000) {
+ // bitmap context-related functions (e.g., CGBitmapContextGetBytesPerRow) can't be used here with macOS 11.0 "Big Sur"
+ static CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
+ int W = [self frame].size.width, H = [self frame].size.height;
+ if (r) { W *= 2; H *= 2; }
+ aux_bitmap = CGBitmapContextCreate(NULL, W, H, 8, 0, cspace, kCGImageAlphaPremultipliedFirst);
+ } else {
+ aux_bitmap = CGBitmapContextCreate(NULL, CGBitmapContextGetWidth(gc), CGBitmapContextGetHeight(gc),
+ CGBitmapContextGetBitsPerComponent(gc), CGBitmapContextGetBytesPerRow(gc),
+ CGBitmapContextGetColorSpace(gc), CGBitmapContextGetBitmapInfo(gc));
+ }
+ if (r) CGContextScaleCTM(aux_bitmap, 2, 2);
}
- (void)reset_aux_bitmap {
CGContextRelease(aux_bitmap);
@@ -2241,20 +2248,26 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
window->clear_damage(FL_DAMAGE_ALL);
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
- if (views_use_CA && !aux_bitmap && !window->as_gl_window()) [self create_aux_bitmap:d->mapped_to_retina()];
+ CGContextRef destination = NULL;
+ if (views_use_CA) {
+ destination = [[NSGraphicsContext currentContext] CGContext];
+ if (!aux_bitmap && !window->as_gl_window()) [self create_aux_bitmap:destination retina:d->mapped_to_retina()];
+ }
#endif
through_drawRect = YES;
if (window->damage()) d->Fl_Window_Driver::flush();
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
- if (views_use_CA) {
- CGContextRef destination = [[NSGraphicsContext currentContext] CGContext];
- if (destination) { // can be NULL with gl_start/gl_finish
+ if (destination) { // can be NULL with gl_start/gl_finish
+ if (fl_mac_os_version < 110000 && CGBitmapContextGetBytesPerRow(aux_bitmap) == CGBitmapContextGetBytesPerRow(destination)) {
+ memcpy(CGBitmapContextGetData(destination), CGBitmapContextGetData(aux_bitmap),
+ CGBitmapContextGetHeight(aux_bitmap) * CGBitmapContextGetBytesPerRow(aux_bitmap));
+ } else {
CGImageRef img = CGBitmapContextCreateImage(aux_bitmap);
CGContextDrawImage(destination, [self frame], img);
CGImageRelease(img);
}
- Fl_Cocoa_Window_Driver::q_release_context();
- }
+ }
+ Fl_Cocoa_Window_Driver::q_release_context();
#endif
if (!through_Fl_X_flush) window->clear_damage();
through_drawRect = NO;