summaryrefslogtreecommitdiff
path: root/src/fl_read_image.cxx
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-09-11 19:45:48 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-09-11 19:45:48 +0200
commitd028f0b37d12636f1956ad59843d2dec96b12a91 (patch)
tree924b4e6a3ea7b15e6e054d534e20aef65671e2d4 /src/fl_read_image.cxx
parent98d8a5da0c6449eb1e976d00368e6469dea4df1d (diff)
Fix fl_read_image() under hybrid Wayland/X11 platform.
Function fl_read_image() obliges to keep a minimal use of global variable fl_window also under the Wayland platform, even if its type (Window) makes little sense for the hybrid library because it has its X11 value (given by X11/X.h) which is not meaningful for the Wayland leg of the hybrid platform. Virtual member function Fl_Surface_Device::as_image_surface() becomes useless.
Diffstat (limited to 'src/fl_read_image.cxx')
-rw-r--r--src/fl_read_image.cxx9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/fl_read_image.cxx b/src/fl_read_image.cxx
index b34585197..181e2a094 100644
--- a/src/fl_read_image.cxx
+++ b/src/fl_read_image.cxx
@@ -40,9 +40,12 @@
uchar *fl_read_image(uchar *p, int X, int Y, int w, int h, int alpha) {
uchar *image_data = NULL;
Fl_RGB_Image *img;
- // TODO: strive to remove use of the fl_window global variable in platform-independent code
- //if (Fl_Surface_Device::surface()->as_image_surface()) { // read from off_screen buffer
- if (fl_find(fl_window)==0) { // read from off_screen buffer
+ // Under macOS and Wayland, fl_window == 0 when an Fl_Image_Surface is the current drawing
+ // surface. Otherwise, fl_window corresponds to a mapped Fl_Window.
+ // Under X11 and windows, fl_window is an offscreen buffer when an Fl_Image_Surface
+ // is the current drawing or when fl_read_image() is called inside the draw() of
+ // an Fl_Double_Window.
+ if (fl_find(fl_window) == 0) { // read from offscreen buffer or buffer of an Fl_Double_Window
img = Fl::screen_driver()->read_win_rectangle(X, Y, w, h, 0);
if (!img) {
return NULL;