Fix Cairo build and add FLTK_OPTION_CAIRO_WINDOW to CI build
Some checks failed
Build and Test / build-linux (push) Has been cancelled
Build and Test / build-wayland (push) Has been cancelled
Build and Test / build-macos (push) Has been cancelled
Build and Test / build-windows (push) Has been cancelled

... on GitHub (GitLab CI builds used it already)
This commit is contained in:
Albrecht Schlosser
2025-11-17 13:53:24 +01:00
parent 4b141bb2f8
commit d623ad08a9
3 changed files with 54 additions and 53 deletions

View File

@@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v4
- name: install prerequisites
run: sudo apt-get update -y && sudo apt-get install -y libasound2-dev libglew-dev libglu1-mesa-dev libx11-dev libxcursor-dev libxft-dev libxinerama-dev
run: sudo apt-get update -y && sudo apt-get install -y libasound2-dev libglew-dev libglu1-mesa-dev libcairo2-dev libx11-dev libxcursor-dev libxft-dev libxinerama-dev
- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
@@ -36,7 +36,7 @@ jobs:
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -D CMAKE_BUILD_TYPE=$BUILD_TYPE -D FLTK_BACKEND_WAYLAND=OFF -D CMAKE_CXX_STANDARD=11 -D CMAKE_CXX_EXTENSIONS=OFF -D FLTK_BUILD_FORMS=ON -D CMAKE_C_FLAGS_INIT="-Wall -Wunused" -D CMAKE_CXX_FLAGS_INIT="-Wall -Wunused"
run: cmake $GITHUB_WORKSPACE -D CMAKE_BUILD_TYPE=$BUILD_TYPE -D FLTK_BACKEND_WAYLAND=OFF -D CMAKE_CXX_STANDARD=11 -D CMAKE_CXX_EXTENSIONS=OFF -D FLTK_BUILD_FORMS=ON -D FLTK_OPTION_CAIRO_WINDOW=ON -D CMAKE_C_FLAGS_INIT="-Wall -Wunused" -D CMAKE_CXX_FLAGS_INIT="-Wall -Wunused"
- name: Build
working-directory: ${{github.workspace}}/build
@@ -57,7 +57,7 @@ jobs:
- uses: actions/checkout@v4
- name: Install prerequisites
run: sudo apt-get update -y && sudo apt-get install -y libasound2-dev libglu1-mesa-dev libwayland-dev wayland-protocols libdbus-1-dev libxkbcommon-dev libegl-dev libopengl-dev libpango1.0-dev libdecor-0-dev libxfixes-dev libxcursor-dev libxinerama-dev
run: sudo apt-get update -y && sudo apt-get install -y libasound2-dev libglu1-mesa-dev libcairo2-dev libwayland-dev wayland-protocols libdbus-1-dev libxkbcommon-dev libegl-dev libopengl-dev libpango1.0-dev libdecor-0-dev libxfixes-dev libxcursor-dev libxinerama-dev
- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
@@ -72,7 +72,7 @@ jobs:
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -D CMAKE_BUILD_TYPE=$BUILD_TYPE -D CMAKE_CXX_STANDARD=11 -D CMAKE_CXX_EXTENSIONS=OFF -D FLTK_BUILD_FORMS=ON -D CMAKE_C_FLAGS_INIT="-Wall -Wunused" -D CMAKE_CXX_FLAGS_INIT="-Wall -Wunused -Wsuggest-override"
run: cmake $GITHUB_WORKSPACE -D CMAKE_BUILD_TYPE=$BUILD_TYPE -D CMAKE_CXX_STANDARD=11 -D CMAKE_CXX_EXTENSIONS=OFF -D FLTK_BUILD_FORMS=ON -D FLTK_OPTION_CAIRO_WINDOW=ON -D CMAKE_C_FLAGS_INIT="-Wall -Wunused" -D CMAKE_CXX_FLAGS_INIT="-Wall -Wunused -Wsuggest-override"
- name: Build
working-directory: ${{github.workspace}}/build

41
FL/Fl.H
View File

@@ -749,50 +749,11 @@ FL_EXPORT extern int args_to_utf8(int argc, char ** &argv);
// Cairo support API
FL_EXPORT extern cairo_t *cairo_make_current(Fl_Window *w);
FL_EXPORT extern void cairo_autolink_context(bool alink);
FL_EXPORT extern bool cairo_autolink_context();
FL_EXPORT extern cairo_t *cairo_cc();
FL_EXPORT extern void cairo_cc(cairo_t *c, bool own=false);
/** 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.
You don't need to use this if you use an Fl_Cairo_Window which does
this automatically after the draw callback returns.
Code example for "Cairo autolink" mode:
In the overridden draw() method of your subclass of Fl_Window or any
widget:
\code
cairo_t *cc = Fl::cairo_cc(); // get the "autolink" Cairo context
// ... your Cairo drawings are here ...
Fl::cairo_flush(cc); // flush Cairo drawings to the device
\endcode
If you configure FLTK with CMake option
\c 'FLTK_OPTION_CAIRO_WINDOW' (i.e. without CMake option
\c 'FLTK_OPTION_CAIRO_EXT') or if you don't enable the \c 'autolink' Cairo
context you may do the equivalent to use Cairo drawings in an
overridden draw() method of derived classes by using
\code
// get the Cairo context for the \c window
cairo_t *cc = Fl::cairo_make_current(window);
// ... your Cairo drawings are here ...
Fl::cairo_flush(cc); // flush Cairo drawings to the device
\endcode
\see Fl::cairo_autolink_context(bool)
\see Fl::cairo_make_current(Fl_Window*);
*/
FL_EXPORT extern void cairo_flush(cairo_t *c) {
// flush Cairo drawings: necessary at least for Windows
cairo_surface_t *s = cairo_get_target(c);
cairo_surface_flush(s);
}
FL_EXPORT extern void cairo_flush(cairo_t *c);
/** @} */

View File

@@ -104,7 +104,7 @@ cairo_t *Fl::cairo_cc() {
\note Only available if built with CMake option FLTK_OPTION_CAIRO_WINDOW=ON.
*/
void Fl::cairo_cc(cairo_t *c, bool own=false) {
void Fl::cairo_cc(cairo_t *c, bool own /* = false */) {
Private::cairo_state_.cc(c, own);
}
@@ -153,22 +153,22 @@ cairo_t *Fl::cairo_make_current(Fl_Window *wi) {
if (!xid->buffer)
return NULL; // this may happen with GL windows
cairo_ctxt = xid->buffer->draw_buffer.cairo_;
cairo_state_.cc(cairo_ctxt, false);
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
cairo_state_.window(0);
Fl::Private::cairo_state_.window(0);
return 0;
}
// don't re-create a context if it's the same gc/window combination
if (fl_gc == Fl::cairo_state_.gc() && fl_xid(wi) == (Window)Fl::cairo_state_.window())
if (fl_gc == Fl::Private::cairo_state_.gc() && fl_xid(wi) == (Window)Fl::Private::cairo_state_.window())
return Fl::cairo_cc();
cairo_state_.window((void *)fl_xid(wi));
Fl::Private::cairo_state_.window((void *)fl_xid(wi));
// Scale the Cairo context appropriately. This is platform dependent
@@ -240,8 +240,8 @@ cairo_t *Fl::Private::cairo_make_current(void *gc) {
cairo_state_.gc(0); // keep track for next time
return 0;
}
if (gc == Fl::cairo_state_.gc() &&
fl_window == (Window)Fl::cairo_state_.window() &&
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
@@ -258,8 +258,8 @@ cairo_t *Fl::Private::cairo_make_current(void *gc) {
\note Only available if CMake FLTK_OPTION_CAIRO_WINDOW is enabled.
*/
cairo_t *Fl::Private::cairo_make_current(void *gc, int W, int H) {
if (gc == Fl::cairo_state_.gc() &&
fl_window == (Window)Fl::cairo_state_.window() &&
if (gc == Fl::Private::cairo_state_.gc() &&
fl_window == (Window)Fl::Private::cairo_state_.window() &&
cairo_state_.cc() != 0) // no need to create a cc, just return that one
return cairo_state_.cc();
@@ -284,9 +284,49 @@ cairo_t *Fl::Private::cairo_make_current(void *gc, int W, int H) {
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.
You don't need to use this if you use an Fl_Cairo_Window which does
this automatically after the draw callback returns.
Code example for "Cairo autolink" mode:
In the overridden draw() method of your subclass of Fl_Window or any
widget:
\code
cairo_t *cc = Fl::cairo_cc(); // get the "autolink" Cairo context
// ... your Cairo drawings are here ...
Fl::cairo_flush(cc); // flush Cairo drawings to the device
\endcode
If you configure FLTK with CMake option
\c 'FLTK_OPTION_CAIRO_WINDOW' (i.e. without CMake option
\c 'FLTK_OPTION_CAIRO_EXT') or if you don't enable the \c 'autolink' Cairo
context you may do the equivalent to use Cairo drawings in an
overridden draw() method of derived classes by using
\code
// get the Cairo context for the \c window
cairo_t *cc = Fl::cairo_make_current(window);
// ... your Cairo drawings are here ...
Fl::cairo_flush(cc); // flush Cairo drawings to the device
\endcode
\see Fl::cairo_autolink_context(bool)
\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
cairo_surface_t *s = cairo_get_target(c);
cairo_surface_flush(s);
}
// Silence compiler warning if none of the Cairo options has been selected
#else
FL_EXPORT int fltk_cairo_dummy() {
return 1;
}