diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2020-08-11 15:18:56 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2020-08-11 15:18:56 +0200 |
| commit | 8f32a29a8b41dee59bfafaa88391deb401e81f37 (patch) | |
| tree | 5c7464c7f6549a21f35a5440552fd2c452b61d40 /src/Fl_cocoa.mm | |
| parent | cd26829099683fda116c3e1b02d9d30b713b6296 (diff) | |
Slightly simpler code in the drawRect:(NSRect) method
Diffstat (limited to 'src/Fl_cocoa.mm')
| -rw-r--r-- | src/Fl_cocoa.mm | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index ddc30e518..d6da12bee 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:(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 |
