summaryrefslogtreecommitdiff
path: root/cairo
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 /cairo
parentb4bbc53c5e7f17395b1d5330598565b60f71e543 (diff)
Fix for issue #426: "configure --enable-cairoext" flips display upside down
Diffstat (limited to 'cairo')
-rw-r--r--cairo/Fl_Cairo.cxx21
1 files changed, 14 insertions, 7 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;