summaryrefslogtreecommitdiff
path: root/src/drivers/Wayland
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2023-08-09 10:31:36 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2023-08-09 10:31:36 +0200
commit1943fe54c8fdf759a3f4da88ea8a8fb5f6f5f7cb (patch)
tree698368755555882244b7eaab9fcbb931e7959fda /src/drivers/Wayland
parent06e8cf98a6a08c202333bff893be55741961bfd3 (diff)
Wayland: fix fl_read_image() from offscreen buffer
Diffstat (limited to 'src/drivers/Wayland')
-rw-r--r--src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx2
-rw-r--r--src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx4
-rw-r--r--src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx10
3 files changed, 10 insertions, 6 deletions
diff --git a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx
index 3fa9c7094..f35ae8543 100644
--- a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx
+++ b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx
@@ -70,7 +70,6 @@ struct fl_wld_buffer *Fl_Wayland_Graphics_Driver::create_shm_buffer(int width, i
wl_shm_pool_set_user_data(pool, pool_data);
}
buffer = (struct fl_wld_buffer*)calloc(1, sizeof(struct fl_wld_buffer));
- buffer->draw_buffer.stride = stride;
buffer->wl_buffer = wl_shm_pool_create_buffer(pool, chunk_offset, width, height, stride, Fl_Wayland_Graphics_Driver::wld_format);
// add this buffer to head of list of current pool's buffers
wl_list_insert(&pool_data->buffers, &buffer->link);
@@ -152,6 +151,7 @@ void Fl_Wayland_Graphics_Driver::buffer_commit(struct wld_window *window,
void Fl_Wayland_Graphics_Driver::cairo_init(struct fl_wld_draw_buffer *buffer, int width, int height, int stride, cairo_format_t format) {
buffer->data_size = stride * height;
+ buffer->stride = stride;
buffer->buffer = new uchar[buffer->data_size];
buffer->width = width;
cairo_surface_t *surf = cairo_image_surface_create_for_data(buffer->buffer, format,
diff --git a/src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx
index 42de33854..1f20d69ef 100644
--- a/src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx
+++ b/src/drivers/Wayland/Fl_Wayland_Image_Surface_Driver.cxx
@@ -33,9 +33,9 @@ Fl_Wayland_Image_Surface_Driver::Fl_Wayland_Image_Surface_Driver(int w, int h, i
h = int(h * d);
}
struct fl_wld_draw_buffer *off_ = (struct fl_wld_draw_buffer*)calloc(1, sizeof(struct fl_wld_draw_buffer));
- off_->stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, w);
offscreen = (Fl_Offscreen)off_;
- Fl_Wayland_Graphics_Driver::cairo_init(off_, w, h, off_->stride, CAIRO_FORMAT_RGB24);
+ Fl_Wayland_Graphics_Driver::cairo_init(off_, w, h,
+ cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, w), CAIRO_FORMAT_RGB24);
}
driver(new Fl_Wayland_Graphics_Driver());
if (d != 1 && high_res) driver()->scale(d);
diff --git a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx
index 764a4e8df..204a058ca 100644
--- a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx
+++ b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx
@@ -1495,9 +1495,13 @@ void Fl_Wayland_Screen_Driver::get_system_colors()
Fl_RGB_Image *Fl_Wayland_Screen_Driver::read_win_rectangle(int X, int Y, int w, int h, Fl_Window *win,
bool ignore, bool *p_ignore) {
struct wld_window* xid = win ? fl_wl_xid(win) : NULL;
- struct fl_wld_draw_buffer *buffer = win ? &xid->buffer->draw_buffer :
- (struct fl_wld_draw_buffer *)
- (((Fl_Image_Surface*)Fl_Surface_Device::surface())->offscreen());//to check
+ if (win && (!xid || !xid->buffer)) return NULL;
+ struct fl_wld_draw_buffer *buffer;
+ if (win) buffer = &xid->buffer->draw_buffer;
+ else {
+ Fl_Image_Surface_Driver *dr = (Fl_Image_Surface_Driver*)Fl_Surface_Device::surface();
+ buffer = (struct fl_wld_draw_buffer *)dr->image_surface()->offscreen();
+ }
float s = win ?
Fl_Wayland_Window_Driver::driver(win)->wld_scale() * scale(win->screen_num()) :
Fl_Surface_Device::surface()->driver()->scale();