summaryrefslogtreecommitdiff
path: root/src/Fl_Cairo.cxx
diff options
context:
space:
mode:
authormaxim nikonov <maxim.nikonov@hqo.co>2026-02-05 15:21:34 +0500
committermaxim nikonov <maxim.nikonov@hqo.co>2026-02-05 15:21:34 +0500
commitdb214d1145e46d527a46d1fc2519548d2c4d23f1 (patch)
treecf0fd9922e4d54f6beb63888f9b28c8e2a787bdf /src/Fl_Cairo.cxx
parent75fc94d6c71fe686f6dde5b41ad91cba2f6bdd6f (diff)
wip: fork
Diffstat (limited to 'src/Fl_Cairo.cxx')
-rw-r--r--src/Fl_Cairo.cxx138
1 files changed, 7 insertions, 131 deletions
diff --git a/src/Fl_Cairo.cxx b/src/Fl_Cairo.cxx
index 1b830c045..20cb08b56 100644
--- a/src/Fl_Cairo.cxx
+++ b/src/Fl_Cairo.cxx
@@ -27,37 +27,9 @@
#ifdef FLTK_HAVE_CAIRO
-// Define USE_MAC_OS for convenience (below). We use macOS specific features
-// if USE_MAC_OS is defined, otherwise we're using X11 (XQuartz) on macOS
-
-#if defined __APPLE__ && !defined(FLTK_USE_X11)
-#define USE_MAC_OS
-#include <ApplicationServices/ApplicationServices.h>
-#endif
-
#include <FL/platform.H>
#include <FL/Fl_Window.H>
-
-// Cairo is currently supported for the following platforms:
-// Windows, macOS (Apple Quartz), X11, Wayland
-
-#if defined(_WIN32) // Windows
-# include <cairo-win32.h>
-#elif defined(FLTK_USE_WAYLAND) // Wayland or hybrid
-# include "../src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H"
-# include "../src/drivers/Wayland/Fl_Wayland_Window_Driver.H"
-# if defined(FLTK_USE_X11)
-# include <cairo-xlib.h>
-# else
- static void *fl_gc = NULL;
-# endif
-#elif defined(FLTK_USE_X11) // X11
-# include <cairo-xlib.h>
-#elif defined(__APPLE__) // macOS
-# include <cairo-quartz.h>
-#else
-# error Cairo is not supported on this platform.
-#endif
+#include <cairo-xlib.h>
// static initialization
@@ -140,24 +112,13 @@ void Fl_Cairo_State::autolink(bool b) {
\note Only available when CMake option '-D FLTK_OPTION_CAIRO_WINDOW' is set.
\return The valid cairo_t *cairo context associated to this window.
- \retval NULL if \a wi is NULL or maybe with GL windows under Wayland
+ \retval NULL if \a wi is NULL
*/
cairo_t *Fl::cairo_make_current(Fl_Window *wi) {
if (!wi)
return NULL;
cairo_t *cairo_ctxt;
-#if defined(FLTK_USE_WAYLAND)
- if (fl_wl_display()) { // true means using wayland backend
- struct wld_window *xid = fl_wl_xid(wi);
- if (!xid || !xid->buffer)
- return NULL; // this may happen with GL windows or if window is not shown
- cairo_ctxt = xid->buffer->draw_buffer.cairo_;
- Fl::Private::cairo_state_.cc(cairo_ctxt, false);
- return cairo_ctxt;
- }
-#endif
-
if (fl_gc == 0) { // means remove current cc
Fl::cairo_cc(0); // destroy any previous cc
Fl::Private::cairo_state_.window(0);
@@ -168,93 +129,23 @@ cairo_t *Fl::cairo_make_current(Fl_Window *wi) {
if (fl_gc == Fl::Private::cairo_state_.gc() && fl_xid(wi) == (Window)Fl::Private::cairo_state_.window())
return Fl::cairo_cc();
- // Scale the Cairo context appropriately. This is platform dependent
-
-#if !defined(USE_MAC_OS)
- float scale = Fl::screen_scale(wi->screen_num()); // get the screen scaling factor
-#endif
-
-#if defined(FLTK_USE_X11)
+ // Scale the Cairo context appropriately
+ float scale = Fl::screen_scale(wi->screen_num());
cairo_ctxt = Fl::Private::cairo_make_current(0, wi->w() * scale, wi->h() * scale);
-#else
- // on macOS, scaling is done before by Fl_Window::make_current(), on Windows, the size is not used
- cairo_ctxt = Fl::Private::cairo_make_current(fl_gc, wi->w(), wi->h());
-#endif
-
Fl::Private::cairo_state_.window((void *)fl_xid(wi));
-
-#if !defined(USE_MAC_OS)
cairo_scale(cairo_ctxt, scale, scale);
-#endif
return cairo_ctxt;
}
/*
- Creates transparently a cairo_surface_t object.
- gc is an HDC context in Windows, a CGContext* in Quartz, and
- a display on X11 (not used on this platform)
+ Creates a cairo_surface_t object using X11/Xlib.
*/
static cairo_surface_t *cairo_create_surface(void *gc, int W, int H) {
-#if defined(FLTK_USE_X11)
return cairo_xlib_surface_create(fl_display, fl_window, fl_visual->visual, W, H);
-#elif defined(FLTK_USE_WAYLAND)
- return NULL;
-#elif defined(_WIN32)
- return cairo_win32_surface_create((HDC)gc);
-#elif defined(__APPLE__)
- return cairo_quartz_surface_create_for_cg_context((CGContextRef)gc, W, H);
-#else
-#error Cairo is not supported on this platform.
-#endif
}
-#if 0 // this non-public function appears not to be used anywhere in FLTK
-/**
- Creates a Cairo context from a \a gc only, gets its window size or
- offscreen size if fl_window is null.
-
- \note Only available if CMake FLTK_OPTION_CAIRO_WINDOW is enabled.
-*/
-cairo_t *Fl::Private::cairo_make_current(void *gc) {
- int W = 0, H = 0;
-#if defined(FLTK_USE_X11) || defined(FLTK_USE_WAYLAND)
- // 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__)
- if (fl_window) {
- W = Fl_Window::current()->w();
- H = Fl_Window::current()->h();
- } else {
- W = CGBitmapContextGetWidth(fl_gc);
- H = CGBitmapContextGetHeight(fl_gc);
- }
-#elif defined(_WIN32)
- // we don't need any W,H for Windows
-#else
-#error Cairo is not supported on this platform.
-#endif
-
- if (!gc) {
- Fl::cairo_cc(0);
- cairo_state_.gc(0); // keep track for next time
- return 0;
- }
- if (gc == Fl::Private::cairo_state_.gc() &&
- fl_window == (Window)Fl::Private::cairo_state_.window() &&
- cairo_state_.cc() != 0)
- return Fl::cairo_cc();
- cairo_state_.gc(fl_gc); // keep track for next time
- cairo_surface_t *s = cairo_create_surface(gc, W, H);
- cairo_t *c = cairo_create(s);
- cairo_surface_destroy(s);
- cairo_state_.cc(c);
- return c;
-}
-#endif
-
/**
Creates a Cairo context from a \p gc and the given size.
@@ -269,29 +160,14 @@ cairo_t *Fl::Private::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(USE_MAC_OS) && 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(USE_MAC_OS) && defined(FLTK_HAVE_CAIROEXT)
- CGContextRestoreGState((CGContextRef)gc);
-#endif
-
cairo_state_.cc(c); // and purge any previously owned context
cairo_surface_destroy(s);
return c;
}
/** Flush Cairo drawings on Cairo context \p c.
- This is \b required on Windows if you use the Cairo context provided
- by the "Cairo autolink" option. Call this when all your drawings on
- the Cairo context are finished. This is maybe not necessary on other
- platforms than Windows but it does no harm if you call it always.
+ Call this when all your drawings on the Cairo context are finished.
You don't need to use this if you use an Fl_Cairo_Window which does
this automatically after the draw callback returns.
@@ -321,7 +197,7 @@ cairo_t *Fl::Private::cairo_make_current(void *gc, int W, int H) {
\see Fl::cairo_make_current(Fl_Window*);
*/
FL_EXPORT extern void Fl::cairo_flush(cairo_t *c) {
- // flush Cairo drawings: necessary at least for Windows
+ // flush Cairo drawings
cairo_surface_t *s = cairo_get_target(c);
cairo_surface_flush(s);
}