summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-04-08 16:22:22 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-04-08 16:22:22 +0200
commit223bf6309b8591843246a966fe5ed23dbab34110 (patch)
tree7e61ff879b66e402657e1cabc4be844011b9c453
parentb4bbc53c5e7f17395b1d5330598565b60f71e543 (diff)
Fix for issue #426: "configure --enable-cairoext" flips display upside down
-rw-r--r--cairo/Fl_Cairo.cxx21
-rw-r--r--src/Fl_cocoa.mm13
2 files changed, 18 insertions, 16 deletions
diff --git a/cairo/Fl_Cairo.cxx b/cairo/Fl_Cairo.cxx
index a6b2043ae..dbbf2e55f 100644
--- a/cairo/Fl_Cairo.cxx
+++ b/cairo/Fl_Cairo.cxx
@@ -14,10 +14,9 @@
// https://www.fltk.org/bugs.php
//
-#include <config.h>
+#include <FL/Fl.H> // includes <FL/fl_config.h>
#ifdef FLTK_HAVE_CAIRO
-#include <FL/Fl.H>
#include <FL/platform.H>
#include <FL/Fl_Window.H>
@@ -28,7 +27,7 @@
# include <cairo-xlib.h>
#elif defined(_WIN32) // Windows
# include <cairo-win32.h>
-#elif defined(__APPLE_QUARTZ__) // macOS
+#elif defined(__APPLE__) // macOS
# include <cairo-quartz.h>
#elif defined(FLTK_USE_WAYLAND)
# include "../src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H"
@@ -78,7 +77,7 @@ cairo_t * Fl::cairo_make_current(Fl_Window* wi) {
if (!xid->buffer) return NULL; // this may happen with GL windows
cairo_ctxt = xid->buffer->cairo_;
cairo_state_.cc(cairo_ctxt, false);
-#else // FLTK_USE_WAYLAND
+#else // !FLTK_USE_WAYLAND
if (fl_gc==0) { // means remove current cc
Fl::cairo_cc(0); // destroy any previous cc
cairo_state_.window(0);
@@ -89,7 +88,7 @@ cairo_t * Fl::cairo_make_current(Fl_Window* wi) {
if (fl_gc==Fl::cairo_state_.gc() && fl_xid(wi) == (Window) Fl::cairo_state_.window())
return Fl::cairo_cc();
- cairo_state_.window(wi);
+ cairo_state_.window((void*)fl_xid(wi));
#ifndef __APPLE__
float scale = Fl::screen_scale(wi->screen_num()); // get the screen scaling factor
@@ -119,7 +118,7 @@ static cairo_surface_t * cairo_create_surface(void * gc, int W, int H) {
return cairo_xlib_surface_create(fl_display, fl_window, fl_visual->visual, W, H);
# elif defined(_WIN32)
return cairo_win32_surface_create((HDC) gc);
-# elif defined(__APPLE_QUARTZ__)
+# elif defined(__APPLE__)
return cairo_quartz_surface_create_for_cg_context((CGContextRef) gc, W, H);
# else
# error Cairo is not supported under this platform.
@@ -137,7 +136,7 @@ cairo_t * Fl::cairo_make_current(void *gc) {
// FIXME X11 get W,H
// gc will be the window handle here
// # warning FIXME get W,H for cairo_make_current(void*)
-#elif defined(__APPLE_QUARTZ__)
+#elif defined(__APPLE__)
if (fl_window) {
W = Fl_Window::current()->w();
H = Fl_Window::current()->h();
@@ -181,7 +180,15 @@ cairo_t * Fl::cairo_make_current(void *gc, int W, int H) {
// we need to (re-)create a fresh cc ...
cairo_state_.gc(gc); // keep track for next time
cairo_surface_t * s = cairo_create_surface(gc, W, H);
+#if defined(__APPLE__) && defined(FLTK_HAVE_CAIROEXT)
+ CGAffineTransform at = CGContextGetCTM((CGContextRef)gc);
+ CGContextSaveGState((CGContextRef)gc);
+ CGContextConcatCTM((CGContextRef)gc, CGAffineTransformInvert(at));
+#endif
cairo_t * c = cairo_create(s);
+#if defined(__APPLE__) && defined(FLTK_HAVE_CAIROEXT)
+ CGContextRestoreGState((CGContextRef)gc);
+#endif
cairo_state_.cc(c); // and purge any previously owned context
cairo_surface_destroy(s);
return c;
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 722472eed..e3cd499c1 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -3479,6 +3479,9 @@ void Fl_Cocoa_Window_Driver::make_current()
gc = (CGContextRef)[nsgc performSelector:gc_sel];
}
Fl_Graphics_Driver::default_driver().gc(gc);
+#if defined(FLTK_HAVE_CAIROEXT)
+ CGContextSaveGState(gc); // one extra level
+#endif
CGContextSaveGState(gc); // native context
// antialiasing must be deactivated because it applies to rectangles too
// and escapes even clipping!!!
@@ -3496,15 +3499,7 @@ void Fl_Cocoa_Window_Driver::make_current()
}
// this is the context with origin at top left of (sub)window
CGContextSaveGState(gc);
-#if defined(FLTK_HAVE_CAIROEXT)
- if (Fl::cairo_autolink_context()) Fl::cairo_make_current(pWindow); // capture gc changes automatically to update the cairo context adequately
-#endif
fl_clip_region( 0 );
-
-#if defined(FLTK_HAVE_CAIROEXT)
- // update the cairo_t context
- if (Fl::cairo_autolink_context()) Fl::cairo_make_current(pWindow);
-#endif
}
// Give the Quartz context back to the system
@@ -3517,7 +3512,7 @@ void Fl_Cocoa_Window_Driver::q_release_context(Fl_Cocoa_Window_Driver *x) {
CGContextFlush(gc);
Fl_Graphics_Driver::default_driver().gc(0);
#if defined(FLTK_HAVE_CAIROEXT)
- if (Fl::cairo_autolink_context()) Fl::cairo_make_current((Fl_Window*) 0); // capture gc changes automatically to update the cairo context adequately
+ CGContextRestoreGState(gc);
#endif
}