Slightly simpler code in the drawRect:(NSRect) method
This commit is contained in:
parent
cd26829099
commit
8f32a29a8b
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user