From 442faf9462ecc6e28373500bc3ecda958054f134 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Sun, 20 Aug 2023 09:10:55 +0200 Subject: Create class function Fl_Wayland_Graphics_Driver::custom_offscreen() --- src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H | 2 ++ src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx | 18 ++++++++++++++++-- .../Wayland/Fl_Wayland_Image_Surface_Driver.cxx | 4 ++-- src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx | 11 ++++------- src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx | 10 ++++------ 5 files changed, 28 insertions(+), 17 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H index d0999037f..9991bd99f 100644 --- a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H +++ b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H @@ -57,6 +57,8 @@ public: static void buffer_commit(struct wld_window *window, struct flCairoRegion *r = NULL); static void cairo_init(struct draw_buffer *buffer, int width, int height, int stride, cairo_format_t format); static struct draw_buffer *offscreen_buffer(Fl_Offscreen); + static const cairo_user_data_key_t key; + static Fl_Image_Surface *custom_offscreen(int w, int h, struct wld_buffer **buffer); }; #endif // FL_WAYLAND_GRAPHICS_DRIVER_H diff --git a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx index 6d8b22a3d..d5e1315a6 100644 --- a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx @@ -17,6 +17,7 @@ #include "Fl_Wayland_Graphics_Driver.H" #include "Fl_Wayland_Screen_Driver.H" #include "Fl_Wayland_Window_Driver.H" +#include #include #include // for close() #include @@ -224,8 +225,21 @@ void Fl_Wayland_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_O cairo_restore(cairo_); } +const cairo_user_data_key_t Fl_Wayland_Graphics_Driver::key = {}; -struct Fl_Wayland_Graphics_Driver::draw_buffer *Fl_Wayland_Graphics_Driver::offscreen_buffer( +struct +Fl_Wayland_Graphics_Driver::draw_buffer *Fl_Wayland_Graphics_Driver::offscreen_buffer( Fl_Offscreen offscreen) { - return (struct draw_buffer*)cairo_get_user_data((cairo_t*)offscreen, NULL); + return (struct draw_buffer*)cairo_get_user_data((cairo_t*)offscreen, &key); +} + + +Fl_Image_Surface *Fl_Wayland_Graphics_Driver::custom_offscreen(int w, int h, + struct Fl_Wayland_Graphics_Driver::wld_buffer **p_off) { + struct Fl_Wayland_Graphics_Driver::wld_buffer *off = + Fl_Wayland_Graphics_Driver::create_shm_buffer(w, h); + *p_off = off; + memset(off->draw_buffer.buffer, 0, off->draw_buffer.data_size); + cairo_set_user_data(off->draw_buffer.cairo_, &key, &off->draw_buffer, NULL); + return new Fl_Image_Surface(w, h, 0, (Fl_Offscreen)off->draw_buffer.cairo_); } diff --git a/src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx index 6d12aa1a2..5c9672179 100644 --- a/src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx @@ -38,8 +38,8 @@ Fl_Wayland_Image_Surface_Driver::Fl_Wayland_Image_Surface_Driver(int w, int h, i Fl_Wayland_Graphics_Driver::cairo_init(off_, w, h, cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, w), CAIRO_FORMAT_RGB24); offscreen = (Fl_Offscreen)off_->cairo_; - cairo_set_user_data(off_->cairo_, NULL, off_, NULL); - } else offscreen = off; + cairo_set_user_data(off_->cairo_, &Fl_Wayland_Graphics_Driver::key, off_, NULL); + } driver(new Fl_Wayland_Graphics_Driver()); if (d != 1 && high_res) driver()->scale(d); } diff --git a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx index d03d53534..11ea1ad51 100644 --- a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx @@ -18,6 +18,7 @@ #include "Fl_Wayland_Window_Driver.H" #include "Fl_Wayland_Screen_Driver.H" #include "Fl_Wayland_Graphics_Driver.H" +#include "Fl_Wayland_Image_Surface_Driver.H" #include #include #include "../../../libdecor/src/libdecor.h" @@ -1622,7 +1623,9 @@ int Fl_Wayland_Window_Driver::set_cursor_4args(const Fl_RGB_Image *rgb, int hotx new_image->image.delay = 0; new_image->offset = 0; //create a Wayland buffer and have it used as an image of the new cursor - struct Fl_Wayland_Graphics_Driver::wld_buffer *offscreen = Fl_Wayland_Graphics_Driver::create_shm_buffer(new_image->image.width, new_image->image.height); + struct Fl_Wayland_Graphics_Driver::wld_buffer *offscreen; + Fl_Image_Surface *img_surf = Fl_Wayland_Graphics_Driver::custom_offscreen( + new_image->image.width, new_image->image.height, &offscreen); new_image->buffer = offscreen->wl_buffer; wl_buffer_set_user_data(new_image->buffer, offscreen); new_cursor->image_count = 1; @@ -1630,15 +1633,9 @@ int Fl_Wayland_Window_Driver::set_cursor_4args(const Fl_RGB_Image *rgb, int hotx new_cursor->images[0] = (struct wl_cursor_image*)new_image; new_cursor->name = strdup("custom cursor"); // draw the rgb image to the cursor's drawing buffer - cairo_set_user_data(offscreen->draw_buffer.cairo_, - NULL, - &offscreen->draw_buffer, - NULL); - Fl_Image_Surface *img_surf = new Fl_Image_Surface(new_image->image.width, new_image->image.height, 0, (Fl_Offscreen)offscreen->draw_buffer.cairo_); Fl_Surface_Device::push_current(img_surf); Fl_Wayland_Graphics_Driver *driver = (Fl_Wayland_Graphics_Driver*)img_surf->driver(); cairo_scale(driver->cr(), scale, scale); - memset(offscreen->draw_buffer.buffer, 0, offscreen->draw_buffer.data_size); ((Fl_RGB_Image*)rgb)->draw(0, 0); Fl_Surface_Device::pop_current(); delete img_surf; diff --git a/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx b/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx index b06748883..7e215a2e5 100644 --- a/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx +++ b/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx @@ -23,6 +23,7 @@ # include # include "Fl_Wayland_Screen_Driver.H" # include "Fl_Wayland_Window_Driver.H" +# include "Fl_Wayland_Image_Surface_Driver.H" # include "../Unix/Fl_Unix_System_Driver.H" # include "Fl_Wayland_Graphics_Driver.H" # include "../../flstring.h" // includes @@ -200,12 +201,9 @@ static struct Fl_Wayland_Graphics_Driver::wld_buffer *offscreen_from_text(const width += 6; width = ceil(width/float(scale)) * scale; // these must be multiples of scale height = ceil(height/float(scale)) * scale; - struct Fl_Wayland_Graphics_Driver::wld_buffer *off = Fl_Wayland_Graphics_Driver::create_shm_buffer(width, height); - memset(off->draw_buffer.buffer, 0, off->draw_buffer.data_size); - cairo_set_user_data(off->draw_buffer.cairo_, - NULL, - &off->draw_buffer, NULL); - Fl_Image_Surface *surf = new Fl_Image_Surface(width, height, 0, (Fl_Offscreen)off->draw_buffer.cairo_); + struct Fl_Wayland_Graphics_Driver::wld_buffer *off; + Fl_Image_Surface *surf = Fl_Wayland_Graphics_Driver::custom_offscreen( + width, height, &off); Fl_Surface_Device::push_current(surf); p = text; fl_font(FL_HELVETICA, 10 * scale); -- cgit v1.2.3