Queue a draw event in open_html
[claws.git] / src / plugins / litehtml_viewer / container_linux.cpp
index 15f8836ad3be5aa77387131077e5afa9116f8eb6..4a455696fbceddceccbfe3ac74148be38d6069ea 100644 (file)
@@ -1,9 +1,7 @@
 /*
  * Claws Mail -- A GTK+ based, lightweight, and fast e-mail client
- * Copyright(C) 1999-2015 the Claws Mail Team
- * == Fancy Plugin ==
- * This file Copyright (C) 2009-2015 Salvatore De Paolis
- * <iwkse@claws-mail.org> and the Claws Mail Team
+ * Copyright(C) 2019 the Claws Mail Team
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 3 of the License, or
@@ -37,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)
@@ -44,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 )
@@ -106,65 +106,6 @@ void container_linux::draw_list_marker( litehtml::uint_ptr hdc, const litehtml::
        }
 }
 
-void container_linux::load_image( const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready )
-{
-       litehtml::tstring url;
-       make_url(src, baseurl, url);
-       bool found = false;
-
-       for (auto ii = m_images.cbegin(); ii != m_images.cend(); ++ii) {
-               const image *i = &(*ii);
-
-               if (!strcmp(i->first.c_str(), url.c_str())) {
-                       found = true;
-                       break;
-               }
-       }
-
-       if(!found)
-       {
-               try
-               {
-                       GdkPixbuf *img = get_image(url.c_str(), true);
-                       if(img)
-                       {
-                               m_images.push_back(std::make_pair(url, img));
-                       }
-               } catch(...)
-               {
-                       int iii=0;
-                       iii++;
-               }
-       }
-}
-
-void container_linux::get_image_size( const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz )
-{
-       litehtml::tstring url;
-       make_url(src, baseurl, url);
-       bool found = false;
-       const image *img = NULL;
-
-       for (auto ii = m_images.cbegin(); ii != m_images.cend(); ++ii) {
-               const image *i = &(*ii);
-               if (i->first == url) {
-                       img = i;
-                       found = true;
-                       break;
-               }
-       }
-
-       if(img != NULL)
-       {
-               sz.width        = gdk_pixbuf_get_width(img->second);
-               sz.height       = gdk_pixbuf_get_height(img->second);
-       } else
-       {
-               sz.width        = 0;
-               sz.height       = 0;
-       }
-}
-
 void container_linux::draw_background( litehtml::uint_ptr hdc, const litehtml::background_paint& bg )
 {
        cairo_t* cr = (cairo_t*) hdc;
@@ -186,22 +127,12 @@ 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();
-       bool found = false;
-       const image *img_i = NULL;
-
-       for (auto ii = m_images.cbegin(); ii != m_images.cend(); ++ii) {
-               const image *i = &(*ii);
-               if (i->first == url) {
-                       img_i = i;
-                       found = true;
-                       break;
-               }
-       }
+       lock_images_cache();
 
-       if(img_i != NULL && img_i->second)
+       auto i = m_images.find(url);
+       if(i != m_images.end() && i->second.first)
        {
-               GdkPixbuf *bgbmp = img_i->second;
+               GdkPixbuf *bgbmp = i->second.first;
 
                GdkPixbuf *new_img;
                if(bg.image_size.width != gdk_pixbuf_get_width(bgbmp) || bg.image_size.height != gdk_pixbuf_get_height(bgbmp))
@@ -247,7 +178,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,56 +585,6 @@ void container_linux::fill_ellipse( cairo_t* cr, int x, int y, int width, int he
        cairo_restore(cr);
 }
 
-void container_linux::clear_images()
-{
-       for(auto i = m_images.begin(); i != m_images.end(); ++i) {
-               image *img = &(*i);
-
-               if (img->second) {
-                       g_object_unref(img->second);
-               }
-       }
-
-       m_images.clear();
-}
-
-gint container_linux::clear_images(gint desired_size)
-{
-       gint size = 0;
-       gint num = 0;
-
-       /* 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
-        * elements later. */
-       for (auto i = m_images.rbegin(); i != m_images.rend(); ++i) {
-               image *img = &(*i);
-               gint cursize;
-
-               if (img->second == NULL)
-                       continue;
-
-               cursize = gdk_pixbuf_get_byte_length(img->second);
-
-               if (size + cursize > desired_size) {
-                       g_object_unref(img->second);
-                       img->second = NULL;
-                       num++;
-               } else {
-                       size += cursize;
-               }
-       }
-
-       /* Remove elements whose GdkPixbuf pointers point to NULL. */
-       m_images.remove_if([&](image _img) -> bool {
-                       if (_img.second == NULL)
-                               return true;
-                       return false;
-                       });
-
-       return num;
-}
-
 std::shared_ptr<litehtml::element>     container_linux::create_element(const litehtml::tchar_t *tag_name,
                                                                                                                                          const litehtml::string_map &attributes,
                                                                                                                                          const std::shared_ptr<litehtml::document> &doc)