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.
This commit is contained in:
ManoloFLTK 2022-09-11 19:45:48 +02:00
parent 98d8a5da0c
commit d028f0b37d
10 changed files with 13 additions and 24 deletions

View File

@ -92,7 +92,6 @@ public:
} }
/** \brief The destructor. */ /** \brief The destructor. */
virtual ~Fl_Surface_Device(); virtual ~Fl_Surface_Device();
virtual Fl_Image_Surface *as_image_surface();
static void push_current(Fl_Surface_Device *new_current); static void push_current(Fl_Surface_Device *new_current);
static Fl_Surface_Device *pop_current(); static Fl_Surface_Device *pop_current();
}; };

View File

@ -82,7 +82,6 @@ public:
int printable_rect(int *w, int *h); int printable_rect(int *w, int *h);
Fl_Offscreen offscreen(); Fl_Offscreen offscreen();
void rescale(); void rescale();
Fl_Image_Surface *as_image_surface();
}; };
@ -113,7 +112,6 @@ protected:
virtual void untranslate() = 0; virtual void untranslate() = 0;
int printable_rect(int *w, int *h); int printable_rect(int *w, int *h);
virtual Fl_RGB_Image *image() = 0; virtual Fl_RGB_Image *image() = 0;
virtual Fl_Image_Surface *as_image_surface();
/** Each platform implements this function its own way. /** Each platform implements this function its own way.
It returns an object implementing all virtual functions It returns an object implementing all virtual functions
of class Fl_Image_Surface_Driver for the plaform. of class Fl_Image_Surface_Driver for the plaform.

View File

@ -39,9 +39,6 @@ class Fl_Window;
# include "mac.H" # include "mac.H"
# elif defined(FLTK_USE_WAYLAND) # elif defined(FLTK_USE_WAYLAND)
# include "wayland.H" # include "wayland.H"
# if !FLTK_USE_X11
typedef struct wld_window *Window;
# endif
# elif defined(FLTK_USE_X11) # elif defined(FLTK_USE_X11)
# include "x11.H" # include "x11.H"
# endif // _WIN32 # endif // _WIN32

View File

@ -45,6 +45,8 @@ extern FL_EXPORT EGLContext fl_wl_glcontext(GLContext rc);
# if FLTK_USE_X11 # if FLTK_USE_X11
// *********** for X11 component *********** // *********** for X11 component ***********
# include "x11.H" # include "x11.H"
# else
typedef struct wld_window *Window;
# endif # endif
#endif // FL_DOXYGEN #endif // FL_DOXYGEN

View File

@ -667,7 +667,7 @@ if (OPTION_USE_WAYLAND)
list (APPEND OPTIONAL_LIBS "-lwayland-cursor -lwayland-client -lxkbcommon -ldl -ldbus-1") list (APPEND OPTIONAL_LIBS "-lwayland-cursor -lwayland-client -lxkbcommon -ldl -ldbus-1")
if (NOT OPTION_WAYLAND_ONLY) if (NOT OPTION_WAYLAND_ONLY)
list (APPEND OPTIONAL_LIBS "-lXcursor -lXrender -lXinerama -lXfixes -lXft -lXext -lX11") list (APPEND OPTIONAL_LIBS "-lXcursor -lXrender -lXinerama -lXfixes -lXft -lXext -lX11")
endif (OPTION_WAYLAND_ONLY) endif (NOT OPTION_WAYLAND_ONLY)
if (GTK_FOUND) if (GTK_FOUND)
list (APPEND OPTIONAL_LIBS ${GTK_LDFLAGS} ) list (APPEND OPTIONAL_LIBS ${GTK_LDFLAGS} )
endif (GTK_FOUND) endif (GTK_FOUND)

View File

@ -97,11 +97,6 @@ Fl_Surface_Device::~Fl_Surface_Device()
if (surface_ == this) surface_ = NULL; 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 */ /** 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) { Fl_Display_Device::Fl_Display_Device(Fl_Graphics_Driver *graphics_driver) : Fl_Surface_Device(graphics_driver) {
this->set_current(); this->set_current();

View File

@ -90,9 +90,6 @@ int Fl_Image_Surface_Driver::printable_rect(int *w, int *h) {
return 0; return 0;
} }
Fl_Image_Surface *Fl_Image_Surface_Driver::as_image_surface() {
return image_surface_;
}
/** /**
\} \}
\endcond \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 // implementation of the fl_XXX_offscreen() functions
static Fl_Image_Surface **offscreen_api_surface = NULL; static Fl_Image_Surface **offscreen_api_surface = NULL;

View File

@ -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); ((Fl_Wayland_Graphics_Driver*)fl_graphics_driver)->set_buffer((struct fl_wld_buffer*)offscreen);
pre_window = Fl_Wayland_Window_Driver::wld_window; pre_window = Fl_Wayland_Window_Driver::wld_window;
Fl_Wayland_Window_Driver::wld_window = NULL; Fl_Wayland_Window_Driver::wld_window = NULL;
fl_window = 0;
} }
void Fl_Wayland_Image_Surface_Driver::end_current() { void Fl_Wayland_Image_Surface_Driver::end_current() {
cairo_surface_t *surf = cairo_get_target(((struct fl_wld_buffer *)offscreen)->cairo_); cairo_surface_t *surf = cairo_get_target(((struct fl_wld_buffer *)offscreen)->cairo_);
cairo_surface_flush(surf); cairo_surface_flush(surf);
Fl_Wayland_Window_Driver::wld_window = pre_window; Fl_Wayland_Window_Driver::wld_window = pre_window;
fl_window = (Window)pre_window;
} }
void Fl_Wayland_Image_Surface_Driver::translate(int x, int y) { void Fl_Wayland_Image_Surface_Driver::translate(int x, int y) {

View File

@ -51,7 +51,7 @@ extern "C" {
#define fl_min(a,b) ((a) < (b) ? (a) : (b)) #define fl_min(a,b) ((a) < (b) ? (a) : (b))
#if !FLTK_USE_X11 #if !FLTK_USE_X11
Window fl_window = 0; // temporary, until we get rid of this global for wayland Window fl_window = 0;
#endif #endif
@ -362,6 +362,7 @@ void Fl_Wayland_Window_Driver::make_current() {
} }
Fl_Wayland_Window_Driver::wld_window = window; Fl_Wayland_Window_Driver::wld_window = window;
fl_window = (Window)window;
float scale = Fl::screen_scale(pWindow->screen_num()) * window->scale; float scale = Fl::screen_scale(pWindow->screen_num()) * window->scale;
if (!window->buffer) { if (!window->buffer) {
window->buffer = Fl_Wayland_Graphics_Driver::create_shm_buffer( window->buffer = Fl_Wayland_Graphics_Driver::create_shm_buffer(

View File

@ -40,9 +40,12 @@
uchar *fl_read_image(uchar *p, int X, int Y, int w, int h, int alpha) { uchar *fl_read_image(uchar *p, int X, int Y, int w, int h, int alpha) {
uchar *image_data = NULL; uchar *image_data = NULL;
Fl_RGB_Image *img; Fl_RGB_Image *img;
// TODO: strive to remove use of the fl_window global variable in platform-independent code // Under macOS and Wayland, fl_window == 0 when an Fl_Image_Surface is the current drawing
//if (Fl_Surface_Device::surface()->as_image_surface()) { // read from off_screen buffer // surface. Otherwise, fl_window corresponds to a mapped Fl_Window.
if (fl_find(fl_window)==0) { // read from off_screen buffer // 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); img = Fl::screen_driver()->read_win_rectangle(X, Y, w, h, 0);
if (!img) { if (!img) {
return NULL; return NULL;