FLTK logo

[master] b8b2805 - Make recent changes to support macOS 11.0 "Big Sur" active with 11.0 only.

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] b8b2805 - Make recent changes to support macOS 11.0 "Big Sur" active with 11.0 only. "ManoloFLTK" Aug 17, 2020  
 
commit b8b280527041710b69e7dd18d721089698abb227
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Mon Aug 17 17:21:44 2020 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Mon Aug 17 17:21:53 2020 +0200

    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.

 src/Fl_cocoa.mm | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git src/Fl_cocoa.mm src/Fl_cocoa.mm
index d6da12b..899f35d 100644
--- src/Fl_cocoa.mm
+++ 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;
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.