FLTK logo

[master] 8f32a29 - Slightly simpler code in the drawRect:(NSRect) method

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

[master] 8f32a29 - Slightly simpler code in the drawRect:(NSRect) method "ManoloFLTK" Aug 11, 2020  
 
commit 8f32a29a8b41dee59bfafaa88391deb401e81f37
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Tue Aug 11 15:18:56 2020 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Tue Aug 11 15:18:56 2020 +0200

    Slightly simpler code in the drawRect:(NSRect) method

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

diff --git src/Fl_cocoa.mm src/Fl_cocoa.mm
index ddc30e5..d6da12b 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:(CGContextRef)gc retina:(BOOL)r;
+- (void)create_aux_bitmap:(BOOL)retina;
 - (void)reset_aux_bitmap;
 #endif
 @end
@@ -2182,12 +2182,12 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
   return NO;
 }
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
-- (void)create_aux_bitmap:(CGContextRef)gc retina:(BOOL)r {
+- (void)create_aux_bitmap:(BOOL)retina {
   int W = [self frame].size.width, H = [self frame].size.height;
-  if (r) { W *= 2; H *= 2; }
+  if (retina) { W *= 2; H *= 2; }
   static CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
-  aux_bitmap = CGBitmapContextCreate(NULL, W, H, 8, 4 * W, cspace, kCGImageAlphaPremultipliedFirst);
-  if (r) CGContextScaleCTM(aux_bitmap, 2, 2);
+  aux_bitmap = CGBitmapContextCreate(NULL, W, H, 8, 0, cspace, kCGImageAlphaPremultipliedFirst);
+  if (retina) CGContextScaleCTM(aux_bitmap, 2, 2);
 }
 - (void)reset_aux_bitmap {
   CGContextRelease(aux_bitmap);
@@ -2220,9 +2220,6 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
   Fl_Window *window = [cw getFl_Window];
   if (!window) return; // may happen after closing full-screen window
   fl_lock_function();
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
-  CGContextRef destination = views_use_CA ? [[NSGraphicsContext currentContext] CGContext] : NULL;
-#endif
   Fl_Cocoa_Window_Driver *d = Fl_Cocoa_Window_Driver::driver(window);
   if (!through_Fl_X_flush
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
@@ -2244,17 +2241,18 @@ 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 (destination && !aux_bitmap) [self create_aux_bitmap:destination retina:d->mapped_to_retina()];
+  if (views_use_CA && !aux_bitmap && !window->as_gl_window()) [self create_aux_bitmap: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 (destination) {
-    // With macOS 11.0, bitmap context-specific functions such as CGBitmapContextGetWidth()
-    // can't be used with destination. Why?
-    CGImageRef img = CGBitmapContextCreateImage(aux_bitmap);
-    CGContextDrawImage(destination, [self frame], img);
-    CGImageRelease(img);
+  if (views_use_CA) {
+    CGContextRef destination = [[NSGraphicsContext currentContext] CGContext];
+    if (destination) { // can be NULL with gl_start/gl_finish
+      CGImageRef img = CGBitmapContextCreateImage(aux_bitmap);
+      CGContextDrawImage(destination, [self frame], img);
+      CGImageRelease(img);
+    }
     Fl_Cocoa_Window_Driver::q_release_context();
     }
 #endif
@@ -3367,12 +3365,6 @@ void Fl_Cocoa_Window_Driver::make_current()
     NSGraphicsContext *nsgc =   through_drawRect ? [NSGraphicsContext currentContext] : [NSGraphicsContext graphicsContextWithWindow:fl_window];
     static SEL gc_sel = fl_mac_os_version >= 101000 ? @selector(CGContext) : @selector(graphicsPort);
     gc = (CGContextRef)[nsgc performSelector:gc_sel];
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
-    if (!gc) { // to support gl_start()/gl_finish()
-      static CGContextRef dummy_gc = CGBitmapContextCreate(NULL, 10, 10, 8, 40, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedFirst);
-      gc = dummy_gc;
-    }
-#endif
   }
   Fl_Graphics_Driver::default_driver().gc(gc);
   CGContextSaveGState(gc); // native context
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

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