summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2023-03-12 15:49:00 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2023-03-12 16:01:58 +0100
commit6e407cb169a3820e3d86e35230bf9b6fea2aef47 (patch)
tree97b18904a48fbf65b27534565e192f4ba155a61b
parent73a2ca5261ee7b0d0e33fc1e49611520d7b0e0cb (diff)
Fix Cairo drawing in test/cairo_test demo for Windows (#694)
On the Windows platform Cairo drawings must be flushed explicitly. This is done in Fl_Cairo_Window after calling the draw callback but it was neither done nor documented in test/cairo_test.cxx when using another type of Window with its overloaded draw() method, i.e. when FLTK was configured with --enable-cairoext or CMake OPTION_CAIROEXT. Note: user code must either explicitly flush the Cairo drawings as done here or destroy the Cairo context which is not done in this demo because the Cairo context should be kept alive.
-rw-r--r--test/cairo_test.cxx12
1 files changed, 10 insertions, 2 deletions
diff --git a/test/cairo_test.cxx b/test/cairo_test.cxx
index ecd87c6ac..86ca7299b 100644
--- a/test/cairo_test.cxx
+++ b/test/cairo_test.cxx
@@ -151,7 +151,7 @@ void draw_image(cairo_t *cr, int w, int h) {
typedef Fl_Cairo_Window cairo_using_window;
-#else // !USE_FL_CAIRO_WINDOW
+#else // !USE_FL_CAIRO_WINDOW || defined(FLTK_HAVE_CAIROEXT)
class cairo_using_window : public Fl_Double_Window {
void (*draw_with_cairo_)(cairo_using_window*, cairo_t*);
@@ -169,7 +169,15 @@ public:
Fl::cairo_make_current(this); // announce Cairo will be used in this window
#endif
cairo_t *cc = Fl::cairo_cc(); // get the adequate Cairo context
- draw_with_cairo_(this, cc); // draw in this window using Cairo
+ draw_with_cairo_(this, cc); // draw in this window using Cairo
+
+ // flush Cairo drawings: necessary at least for Windows
+ // see also FL/Fl_Cairo_Window.H
+ // FIXME: this should be simplified with an FLTK API, for instance:
+ // Fl::cairo_flush(cc);
+
+ cairo_surface_t *s = cairo_get_target(Fl::cairo_cc());
+ cairo_surface_flush(s);
}
void set_draw_cb( void (*cb)(cairo_using_window*, cairo_t*)) {
draw_with_cairo_ = cb;