FLTK logo

[master] 97ae3b2 - Wayland platform: add missing deallocator for cached images.

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 97ae3b2 - Wayland platform: add missing deallocator for cached images. "ManoloFLTK" Dec 02, 2021  
 
commit 97ae3b224704dd2f3ce825d3c3702110daed6cc1
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Sat May 29 08:05:51 2021 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Wed Sep 29 12:14:55 2021 +0200

    Wayland platform: add missing deallocator for cached images.

 src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx
index 545fce7..7c8ea38 100644
--- src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx
+++ src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx
@@ -696,6 +696,13 @@ void Fl_Wayland_Graphics_Driver::draw_rgb(Fl_RGB_Image *rgb,int XP, int YP, int
 }
 
 
+static cairo_user_data_key_t data_key_for_surface = {};
+
+static void dealloc_surface_data(void *data) {
+  delete[] (uchar*)data;
+}
+
+
 void Fl_Wayland_Graphics_Driver::cache(Fl_RGB_Image *rgb) {
   int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, rgb->data_w());
   uchar *BGRA = new uchar[stride * rgb->data_h()];
@@ -743,6 +750,7 @@ void Fl_Wayland_Graphics_Driver::cache(Fl_RGB_Image *rgb) {
   }
   cairo_surface_t *surf = cairo_image_surface_create_for_data(BGRA, CAIRO_FORMAT_ARGB32, rgb->data_w(), rgb->data_h(), stride);
   if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS) return;
+  (void)cairo_surface_set_user_data(surf, &data_key_for_surface, BGRA, dealloc_surface_data);
   cairo_pattern_t *pat = cairo_pattern_create_for_surface(surf);
   *Fl_Graphics_Driver::id(rgb) = (fl_uintptr_t)pat;
 }
@@ -798,6 +806,7 @@ void Fl_Wayland_Graphics_Driver::cache(Fl_Bitmap *bm) {
     }
   cairo_surface_t *surf = cairo_image_surface_create_for_data(BGRA, CAIRO_FORMAT_A1, bm->data_w(), bm->data_h(), stride);
   if (cairo_surface_status(surf) == CAIRO_STATUS_SUCCESS) {
+    (void)cairo_surface_set_user_data(surf, &data_key_for_surface, BGRA, dealloc_surface_data);
     cairo_pattern_t *pat = cairo_pattern_create_for_surface(surf);
     *Fl_Graphics_Driver::id(bm) = (fl_uintptr_t)pat;
   }
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.