Add a mutex lock for Litehtml plugin image cache
authorAndrej Kacian <ticho@claws-mail.org>
Tue, 5 Mar 2019 07:40:20 +0000 (08:40 +0100)
committerAndrej Kacian <ticho@claws-mail.org>
Tue, 5 Mar 2019 07:44:29 +0000 (08:44 +0100)
src/plugins/litehtml_viewer/container_linux.cpp
src/plugins/litehtml_viewer/container_linux.h

index 9a11757..e64d413 100644 (file)
@@ -35,6 +35,7 @@ container_linux::container_linux(void)
 {
        m_temp_surface  = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 2, 2);
        m_temp_cr               = cairo_create(m_temp_surface);
+       g_rec_mutex_init(&m_images_lock);
 }
 
 container_linux::~container_linux(void)
@@ -42,6 +43,7 @@ container_linux::~container_linux(void)
        clear_images();
        cairo_surface_destroy(m_temp_surface);
        cairo_destroy(m_temp_cr);
+       g_rec_mutex_clear(&m_images_lock);
 }
 
 int container_linux::pt_to_px( int pt )
@@ -184,7 +186,7 @@ void container_linux::draw_background( litehtml::uint_ptr hdc, const litehtml::b
        litehtml::tstring url;
        make_url(bg.image.c_str(), bg.baseurl.c_str(), url);
 
-       //lock_images_cache();
+       lock_images_cache();
        bool found = false;
        const image *img_i = NULL;
 
@@ -245,7 +247,8 @@ void container_linux::draw_background( litehtml::uint_ptr hdc, const litehtml::b
                cairo_surface_destroy(img);
 
        }
-//     unlock_images_cache();
+
+       unlock_images_cache();
        cairo_restore(cr);
 }
 
@@ -653,6 +656,8 @@ void container_linux::fill_ellipse( cairo_t* cr, int x, int y, int width, int he
 
 void container_linux::clear_images()
 {
+       lock_images_cache();
+
        for(auto i = m_images.begin(); i != m_images.end(); ++i) {
                image *img = &(*i);
 
@@ -662,6 +667,8 @@ void container_linux::clear_images()
        }
 
        m_images.clear();
+
+       unlock_images_cache();
 }
 
 gint container_linux::clear_images(gint desired_size)
@@ -669,6 +676,8 @@ gint container_linux::clear_images(gint desired_size)
        gint size = 0;
        gint num = 0;
 
+       lock_images_cache();
+
        /* First, tally up size of all the stored GdkPixbufs and
         * deallocate those which make the total size be above
         * the desired_size limit. We will remove their list
@@ -698,6 +707,8 @@ gint container_linux::clear_images(gint desired_size)
                        return false;
                        });
 
+       unlock_images_cache();
+
        return num;
 }
 
index a68502d..0b5f006 100644 (file)
@@ -61,7 +61,9 @@ protected:
        cairo_surface_t*                        m_temp_surface;
        cairo_t*                                        m_temp_cr;
        images_map                                      m_images;
-    cairo_clip_box::vector             m_clips;
+       GRecMutex                                       m_images_lock;
+       cairo_clip_box::vector                          m_clips;
+
 public:
        container_linux(void);
        virtual ~container_linux(void);
@@ -104,4 +106,6 @@ private:
        void                                                            add_path_arc(cairo_t* cr, double x, double y, double rx, double ry, double a1, double a2, bool neg);
        void                                                            draw_pixbuf(cairo_t* cr, const GdkPixbuf *bmp, int x, int y, int cx, int cy);
        cairo_surface_t*                                        surface_from_pixbuf(const GdkPixbuf *bmp);
+       void lock_images_cache(void);
+       void unlock_images_cache(void);
 };