diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-09-11 19:45:48 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-09-11 19:45:48 +0200 |
| commit | d028f0b37d12636f1956ad59843d2dec96b12a91 (patch) | |
| tree | 924b4e6a3ea7b15e6e054d534e20aef65671e2d4 /src | |
| parent | 98d8a5da0c6449eb1e976d00368e6469dea4df1d (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')
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/Fl_Device.cxx | 5 | ||||
| -rw-r--r-- | src/Fl_Image_Surface.cxx | 8 | ||||
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx | 2 | ||||
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx | 3 | ||||
| -rw-r--r-- | src/fl_read_image.cxx | 9 |
6 files changed, 11 insertions, 18 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 86fd019fe..9376a02c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -667,7 +667,7 @@ if (OPTION_USE_WAYLAND) list (APPEND OPTIONAL_LIBS "-lwayland-cursor -lwayland-client -lxkbcommon -ldl -ldbus-1") if (NOT OPTION_WAYLAND_ONLY) list (APPEND OPTIONAL_LIBS "-lXcursor -lXrender -lXinerama -lXfixes -lXft -lXext -lX11") - endif (OPTION_WAYLAND_ONLY) + endif (NOT OPTION_WAYLAND_ONLY) if (GTK_FOUND) list (APPEND OPTIONAL_LIBS ${GTK_LDFLAGS} ) endif (GTK_FOUND) diff --git a/src/Fl_Device.cxx b/src/Fl_Device.cxx index d5e1b27c4..e3ccca9d6 100644 --- a/src/Fl_Device.cxx +++ b/src/Fl_Device.cxx @@ -97,11 +97,6 @@ Fl_Surface_Device::~Fl_Surface_Device() if (surface_ == this) surface_ = NULL; } -/** Returns non-NULL if this surface is an Fl_Image_Surface object - \version 1.4.0 - */ -Fl_Image_Surface *Fl_Surface_Device::as_image_surface() { return NULL; } - /** A constructor that sets the graphics driver used by the display */ Fl_Display_Device::Fl_Display_Device(Fl_Graphics_Driver *graphics_driver) : Fl_Surface_Device(graphics_driver) { this->set_current(); diff --git a/src/Fl_Image_Surface.cxx b/src/Fl_Image_Surface.cxx index 1a5f5ec31..d1a19c6ff 100644 --- a/src/Fl_Image_Surface.cxx +++ b/src/Fl_Image_Surface.cxx @@ -90,9 +90,6 @@ int Fl_Image_Surface_Driver::printable_rect(int *w, int *h) { return 0; } -Fl_Image_Surface *Fl_Image_Surface_Driver::as_image_surface() { - return image_surface_; -} /** \} \endcond @@ -155,11 +152,6 @@ void Fl_Image_Surface::rescale() { } -Fl_Image_Surface *Fl_Image_Surface::as_image_surface() { - return this; -} - - // implementation of the fl_XXX_offscreen() functions static Fl_Image_Surface **offscreen_api_surface = NULL; diff --git a/src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx index 4f64434d8..b3dcc179c 100644 --- a/src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx @@ -60,12 +60,14 @@ void Fl_Wayland_Image_Surface_Driver::set_current() { ((Fl_Wayland_Graphics_Driver*)fl_graphics_driver)->set_buffer((struct fl_wld_buffer*)offscreen); pre_window = Fl_Wayland_Window_Driver::wld_window; Fl_Wayland_Window_Driver::wld_window = NULL; + fl_window = 0; } void Fl_Wayland_Image_Surface_Driver::end_current() { cairo_surface_t *surf = cairo_get_target(((struct fl_wld_buffer *)offscreen)->cairo_); cairo_surface_flush(surf); Fl_Wayland_Window_Driver::wld_window = pre_window; + fl_window = (Window)pre_window; } void Fl_Wayland_Image_Surface_Driver::translate(int x, int y) { diff --git a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx index e35cfddcb..43c3d3f1b 100644 --- a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx @@ -51,7 +51,7 @@ extern "C" { #define fl_min(a,b) ((a) < (b) ? (a) : (b)) #if !FLTK_USE_X11 -Window fl_window = 0; // temporary, until we get rid of this global for wayland +Window fl_window = 0; #endif @@ -362,6 +362,7 @@ void Fl_Wayland_Window_Driver::make_current() { } Fl_Wayland_Window_Driver::wld_window = window; + fl_window = (Window)window; float scale = Fl::screen_scale(pWindow->screen_num()) * window->scale; if (!window->buffer) { window->buffer = Fl_Wayland_Graphics_Driver::create_shm_buffer( 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; |
