Wayland: fix fl_read_image() from offscreen buffer

This commit is contained in:
ManoloFLTK 2023-08-09 10:31:36 +02:00
parent 06e8cf98a6
commit 1943fe54c8
4 changed files with 13 additions and 6 deletions

View File

@ -117,6 +117,9 @@ protected:
of class Fl_Image_Surface_Driver for the plaform.
*/
static Fl_Image_Surface_Driver *newImageSurfaceDriver(int w, int h, int high_res, Fl_Offscreen off);
public:
/** Returns pointer to the associated Fl_Image_Surface object */
Fl_Image_Surface *image_surface() { return image_surface_; }
};
/**

View File

@ -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,

View File

@ -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);

View File

@ -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();