From 6467a4ada01a1c45ade557dde7cb09b4a4f92e48 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Mon, 5 Nov 2018 09:04:38 +0000 Subject: [PATCH] MacOS: fix support of Cairo under macOS 10.14 Mojave. The cairo_test program would redraw the window vertically flipped after the window was hidden or miniaturized when layer-backed windows were used. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@13111 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Fl.H | 3 +++ cairo/Fl_Cairo.cxx | 7 +++++++ src/Fl_cocoa.mm | 15 +++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/FL/Fl.H b/FL/Fl.H index a8f1db765..03924b234 100644 --- a/FL/Fl.H +++ b/FL/Fl.H @@ -166,6 +166,9 @@ public: // should be private! static int compose_state; // used for dead keys (WIN32) or marked text (MacOS) static void call_screen_init(); // recompute screen number and dimensions #ifdef __APPLE__ +# ifdef FLTK_HAVE_CAIRO + static bool using_cairo_context; +# endif static void reset_marked_text(); // resets marked text static void insertion_point_location(int x, int y, int height); // sets window coordinates & height of insertion point #endif diff --git a/cairo/Fl_Cairo.cxx b/cairo/Fl_Cairo.cxx index 6207d3c2e..6208272b2 100644 --- a/cairo/Fl_Cairo.cxx +++ b/cairo/Fl_Cairo.cxx @@ -34,6 +34,7 @@ # elif defined(WIN32) # include # elif defined(__APPLE_QUARTZ__) +bool Fl::using_cairo_context = false; # include # else # error Cairo is not supported on this platform. @@ -78,9 +79,15 @@ cairo_t * Fl::cairo_make_current(Fl_Window* wi) { if (fl_gc==0) { // means remove current cc Fl::cairo_cc(0); // destroy any previous cc cairo_state_.window(0); +#if defined(__APPLE_QUARTZ__) + Fl::using_cairo_context = false; +#endif return 0; } +#if defined(__APPLE_QUARTZ__) + Fl::using_cairo_context = true; +#endif // don't re-create a context if it's the same gc/window couple if (fl_gc==Fl::cairo_state_.gc() && fl_xid(wi) == (Window) Fl::cairo_state_.window()) return Fl::cairo_cc(); diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index cd4060e78..36c67a2e0 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -36,9 +36,8 @@ extern "C" { #include } - -#include #include +#include #include #include #include @@ -2421,8 +2420,20 @@ static CGContextRef prepare_bitmap_for_layer(int w, int h ) { } if (window->damage()) { through_drawRect = YES; +#ifdef FLTK_HAVE_CAIRO + CGFloat before_flush = CGContextGetCTM(layer_gc).d; + Fl::using_cairo_context = false; +#endif i->flush(); Fl_X::q_release_context(); +#ifdef FLTK_HAVE_CAIRO + if (Fl::using_cairo_context && CGContextGetCTM(layer_gc).d != before_flush ) { + // necessary for Cairo and layer-backed views + CGContextRestoreGState(layer_gc); + CGContextSaveGState(layer_gc); + } + Fl::using_cairo_context = false; +#endif through_drawRect = NO; window->clear_damage(); if (layer_gc) {