summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-06-01 11:04:35 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-06-01 11:04:46 +0200
commit61d9035e997da09696f3dc7d30e3bc558ce97021 (patch)
treee57dbbe22891c2aa169eeeb1ed81a2e978489be3
parent897b903f163b5d745afe8c8df92c8609f9ea51b5 (diff)
Avoid repeated calls to CGBitmapContextGetBytesPerRow().
-rw-r--r--src/Fl_cocoa.mm17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index d368d036d..d964792bf 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -2241,6 +2241,10 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
fl_lock_function();
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
CGContextRef gc = views_use_CA ? [[NSGraphicsContext currentContext] CGContext] : NULL;
+ // this condition (unchanged W and H but changed BytesPerRow) occurs with 10.15
+ size_t to_copy = gc && (!aux_bitmap ||
+ (CGBitmapContextGetBytesPerRow(gc) == CGBitmapContextGetBytesPerRow(aux_bitmap))) ?
+ CGBitmapContextGetHeight(gc) * CGBitmapContextGetBytesPerRow(gc) : 0;
#endif
Fl_Cocoa_Window_Driver *d = Fl_Cocoa_Window_Driver::driver(window);
if (!through_Fl_X_flush
@@ -2264,13 +2268,12 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
else if (gc && aux_bitmap && ( Fl_X::i(window)->region || !(window->damage()&FL_DAMAGE_ALL)) ) {
- if (CGBitmapContextGetBytesPerRow(gc) != CGBitmapContextGetBytesPerRow(aux_bitmap)) {
- // this condition (unchanged W and H but changed BytesPerRow) occurs with 10.15
+ if (to_copy) {
+ memcpy(CGBitmapContextGetData(gc), CGBitmapContextGetData(aux_bitmap), to_copy);
+ } else {
CGImageRef img = CGBitmapContextCreateImage(aux_bitmap);
CGContextDrawImage(gc, [self frame], img);
CGImageRelease(img);
- } else {
- memcpy(CGBitmapContextGetData(gc), CGBitmapContextGetData(aux_bitmap), CGBitmapContextGetHeight(gc) * CGBitmapContextGetBytesPerRow(gc));
}
}
#endif
@@ -2280,12 +2283,12 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
if (window->damage()) {
d->Fl_Window_Driver::flush();
if (!aux_bitmap) [self create_aux_bitmap:gc retina:d->mapped_to_retina()];
- if (CGBitmapContextGetBytesPerRow(gc) != CGBitmapContextGetBytesPerRow(aux_bitmap)) {
+ if (to_copy) {
+ memcpy(CGBitmapContextGetData(aux_bitmap), CGBitmapContextGetData(gc), to_copy);
+ } else {
CGImageRef img = CGBitmapContextCreateImage(gc);
CGContextDrawImage(aux_bitmap, [self frame], img);
CGImageRelease(img);
- } else {
- memcpy(CGBitmapContextGetData(aux_bitmap), CGBitmapContextGetData(gc), CGBitmapContextGetHeight(gc) * CGBitmapContextGetBytesPerRow(gc));
}
}
Fl_Cocoa_Window_Driver::q_release_context();