[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - 3 commits - sc/inc vcl/inc vcl/source vcl/unx

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Fri Apr 16 08:56:36 UTC 2021


 sc/inc/formulacell.hxx                         |   22 +++-
 vcl/inc/unx/fontmanager.hxx                    |    5 -
 vcl/source/font/PhysicalFontCollection.cxx     |    3 
 vcl/unx/generic/fontmanager/fontconfig.cxx     |  122 ++++++++++++++++++++++---
 vcl/unx/generic/gdi/freetypetextrender.cxx     |    1 
 vcl/unx/generic/glyphs/freetype_glyphcache.cxx |   11 --
 6 files changed, 136 insertions(+), 28 deletions(-)

New commits:
commit 6f31946c9dd8ee24909e8d3070f4aa5dba8e9849
Author:     Luboš Luňák <l.lunak at centrum.cz>
AuthorDate: Thu Feb 25 20:59:45 2021 +0000
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Fri Apr 16 10:55:58 2021 +0200

    do not repeatedly call getenv("SAL_NO_FONT_LOOKUP")
    
    In the profiling data I see it actually takes 1% of the CPU time.
    
    Change-Id: I55de0191ac9fb17095e7d137f4efc1735936e233
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111571
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
    (cherry picked from commit 6457ade879b90a6d84871cefe46e17e30e68920e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114173

diff --git a/vcl/source/font/PhysicalFontCollection.cxx b/vcl/source/font/PhysicalFontCollection.cxx
index 6741f79faae2..5606b321af15 100644
--- a/vcl/source/font/PhysicalFontCollection.cxx
+++ b/vcl/source/font/PhysicalFontCollection.cxx
@@ -948,7 +948,8 @@ PhysicalFontFamily* PhysicalFontCollection::FindFontFamily( FontSelectPattern& r
     if( !Count() )
         return nullptr;
 
-    if (getenv("SAL_NO_FONT_LOOKUP") != nullptr)
+    static bool noFontLookup = getenv("SAL_NO_FONT_LOOKUP") != nullptr;
+    if (noFontLookup)
     {
         // Hard code the use of Liberation Sans and skip font search.
         sal_Int32 nIndex = 0;
commit 2cee03ec64fc93d3014a92990f98b402ed125824
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Thu Apr 1 23:51:46 2021 +0200
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Fri Apr 16 10:55:51 2021 +0200

    Work around assert() in circular reference within group calc, tdf#141146
    
    Triggered by crash test loading document of
    wget 'https://bz.apache.org/ooo/attachment.cgi?id=71756' -O ooo114587-1.ods
    
    after
    
        commit 042dbf83122b14fd1dd32705c8f8b7d65c22f21b
        CommitDate: Thu Mar 25 16:31:29 2021 +0100
    
            Resolves: tdf#141146 Fix LOOKUP in array with result
            scalar / single reference
    
    Though could happen any time whenever a shared formula group calc
    attempts to obtain a result from an already running cell.
    
    Change-Id: Id668b31a8d81389c593c6fd2191fd444efcdb70f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113494
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit 465b8b0e9ad4b0c9c7701dee2820a99c5d00b5bf)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113633
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 9be8b84df8a9..a6701bcbf0bd 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -23,11 +23,13 @@
 #include <memory>
 
 #include <formula/tokenarray.hxx>
+#include <formula/errorcodes.hxx>
 #include <svl/listener.hxx>
 
 #include "types.hxx"
 #include "interpretercontext.hxx"
 #include "document.hxx"
+#include "docoptio.hxx"
 #include "formulalogger.hxx"
 #include "formularesult.hxx"
 
@@ -437,15 +439,25 @@ public:
         return (rDocument.GetAutoCalc() || (cMatrixFlag != ScMatrixMode::NONE));
     }
 
-    bool MaybeInterpret()
+    void MaybeInterpret()
     {
         if (NeedsInterpret())
         {
-            assert(!rDocument.IsThreadedGroupCalcInProgress());
-            Interpret();
-            return true;
+            if (bRunning && !rDocument.GetDocOptions().IsIter() && rDocument.IsThreadedGroupCalcInProgress())
+            {
+                // This is actually copied from Interpret()'s if(bRunning)
+                // block that once caught this circular reference but now is
+                // prepended with various threaded group calc things which the
+                // assert() below is supposed to fail on when entering again.
+                // Nevertheless, we need some state here the caller can obtain.
+                aResult.SetResultError( FormulaError::CircularReference );
+            }
+            else
+            {
+                assert(!rDocument.IsThreadedGroupCalcInProgress());
+                Interpret();
+            }
         }
-        return false;
     }
 
     /**
commit 92114ede4348dc200d9fe5bb6f13e3d968cb5059
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed Apr 14 09:57:33 2021 +0100
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Fri Apr 16 10:55:45 2021 +0200

    tdf#140639 cache FcPattern for font options
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114083
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    
    also includes...
    
    getFontOptions is always called with pitch of PITCH_DONTKNOW
    
    getFontOptions is called from only one location and there
    the pitch value is left at its default PITCH_DONTKNOW
    which is suspicious but that's the way it currently is
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114076
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    
    use original FontAttributes instead of an intermediate FastPrintFontInfo
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114077
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    
    hintstyle is unused
    
    left behind after...
    
    commit 561a02ec72cf963d7cd59cfb9a183c1032f0861b
    Date:   Thu Jun 15 15:28:46 2017 +0200
    
        loplugin:unusedfields in vcl part3
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114068
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    
    Change-Id: Ibb1b1e06630e505924e05ea4b5b454e58738d743
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114140
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/vcl/inc/unx/fontmanager.hxx b/vcl/inc/unx/fontmanager.hxx
index 7d625555d833..2b0ace42b6c2 100644
--- a/vcl/inc/unx/fontmanager.hxx
+++ b/vcl/inc/unx/fontmanager.hxx
@@ -39,6 +39,7 @@
  *  friends are PostScript afm style, that is they are 1/1000 font height
  */
 
+class FontAttributes;
 class FontSubsetInfo;
 class FontConfigFontOptions;
 class FontSelectPattern;
@@ -309,7 +310,9 @@ public:
     in different fonts in e.g. english and japanese
      */
     void matchFont( FastPrintFontInfo& rInfo, const css::lang::Locale& rLocale );
-    static std::unique_ptr<FontConfigFontOptions> getFontOptions( const FastPrintFontInfo&, int nSize);
+
+    static std::unique_ptr<FontConfigFontOptions> getFontOptions(const FontAttributes& rFontAttributes, int nSize);
+    static void clearFontOptionsCache();
 
     void Substitute(FontSelectPattern &rPattern, OUString& rMissingCodes);
 
diff --git a/vcl/unx/generic/fontmanager/fontconfig.cxx b/vcl/unx/generic/fontmanager/fontconfig.cxx
index 65cba56e069c..87b4df42ceab 100644
--- a/vcl/unx/generic/fontmanager/fontconfig.cxx
+++ b/vcl/unx/generic/fontmanager/fontconfig.cxx
@@ -18,6 +18,9 @@
  */
 
 #include <memory>
+#include <string_view>
+
+#include <o3tl/lru_map.hxx>
 #include <unx/fontmanager.hxx>
 #include <unx/helper.hxx>
 #include <comphelper/sequence.hxx>
@@ -44,6 +47,7 @@ using namespace psp;
 
 #include <osl/process.h>
 
+#include <boost/functional/hash.hpp>
 #include <utility>
 #include <algorithm>
 
@@ -51,7 +55,92 @@ using namespace osl;
 
 namespace
 {
-    typedef std::pair<FcChar8*, FcChar8*> lang_and_element;
+
+struct FontOptionsKey
+{
+    OUString m_sFamilyName;
+    int m_nFontSize;
+    FontItalic m_eItalic;
+    FontWeight m_eWeight;
+    FontWidth m_eWidth;
+
+    bool operator==(const FontOptionsKey& rOther) const
+    {
+        return m_sFamilyName == rOther.m_sFamilyName &&
+               m_nFontSize == rOther.m_nFontSize &&
+               m_eItalic == rOther.m_eItalic &&
+               m_eWeight == rOther.m_eWeight &&
+               m_eWidth == rOther.m_eWidth;
+    }
+};
+
+}
+
+namespace std
+{
+
+template <> struct hash<FontOptionsKey>
+{
+    std::size_t operator()(const FontOptionsKey& k) const noexcept
+    {
+        std::size_t seed = k.m_sFamilyName.hashCode();
+        boost::hash_combine(seed, k.m_nFontSize);
+        boost::hash_combine(seed, k.m_eItalic);
+        boost::hash_combine(seed, k.m_eWeight);
+        boost::hash_combine(seed, k.m_eWidth);
+        return seed;
+    }
+};
+
+} // end std namespace
+
+namespace
+{
+
+struct FcPatternDeleter
+{
+    void operator()(FcPattern* pPattern) const
+    {
+        FcPatternDestroy(pPattern);
+    }
+};
+
+typedef std::unique_ptr<FcPattern, FcPatternDeleter> FcPatternUniquePtr;
+
+class CachedFontConfigFontOptions
+{
+private:
+    FontOptionsKey m_aKey;
+    std::unique_ptr<FontConfigFontOptions> m_xLastFontOptions;
+
+    o3tl::lru_map<FontOptionsKey, FcPatternUniquePtr> lru_options_cache;
+
+public:
+    CachedFontConfigFontOptions()
+        : lru_options_cache(10) // arbitrary cache size of 10
+    {
+    }
+
+    std::unique_ptr<FontConfigFontOptions> lookup(const FontOptionsKey& rKey)
+    {
+        auto it = lru_options_cache.find(rKey);
+        if (it != lru_options_cache.end())
+            return std::make_unique<FontConfigFontOptions>(FcPatternDuplicate(it->second.get()));
+        return nullptr;
+    }
+
+    void cache(const FontOptionsKey& rKey, const FcPattern* pPattern)
+    {
+        lru_options_cache.insert(std::make_pair(rKey, FcPatternUniquePtr(FcPatternDuplicate(pPattern))));
+    }
+
+    void clear()
+    {
+        m_xLastFontOptions.reset();
+    }
+};
+
+typedef std::pair<FcChar8*, FcChar8*> lang_and_element;
 
 class FontCfgWrapper
 {
@@ -76,6 +165,7 @@ public:
 //to-do, make private and add some cleaner accessor methods
     std::unordered_map< OString, OString > m_aFontNameToLocalized;
     std::unordered_map< OString, OString > m_aLocalizedToCanonical;
+    CachedFontConfigFontOptions m_aCachedFontOptions;
 private:
     void cacheLocalizedFontNames(const FcChar8 *origfontname, const FcChar8 *bestfontname, const std::vector< lang_and_element > &lang_and_elements);
 
@@ -367,6 +457,7 @@ void FontCfgWrapper::clear()
         m_pFontSet = nullptr;
     }
     m_pLanguageTag.reset();
+    m_aCachedFontOptions.clear();
 }
 
 /*
@@ -1095,15 +1186,20 @@ void FontConfigFontOptions::SyncPattern(const OString& rFileName, sal_uInt32 nIn
     FcPatternAddBool(mpPattern, FC_EMBOLDEN, bEmbolden ? FcTrue : FcFalse);
 }
 
-std::unique_ptr<FontConfigFontOptions> PrintFontManager::getFontOptions(const FastPrintFontInfo& rInfo, int nSize)
+std::unique_ptr<FontConfigFontOptions> PrintFontManager::getFontOptions(const FontAttributes& rInfo, int nSize)
 {
+    FontOptionsKey aKey{ rInfo.GetFamilyName(), nSize, rInfo.GetItalic(), rInfo.GetWeight(), rInfo.GetWidthType() };
+
     FontCfgWrapper& rWrapper = FontCfgWrapper::get();
 
-    std::unique_ptr<FontConfigFontOptions> pOptions;
+    std::unique_ptr<FontConfigFontOptions> pOptions = rWrapper.m_aCachedFontOptions.lookup(aKey);
+    if (pOptions)
+        return pOptions;
+
     FcConfig* pConfig = FcConfigGetCurrent();
     FcPattern* pPattern = FcPatternCreate();
 
-    OString sFamily = OUStringToOString( rInfo.m_aFamilyName, RTL_TEXTENCODING_UTF8 );
+    OString sFamily = OUStringToOString(aKey.m_sFamilyName, RTL_TEXTENCODING_UTF8);
 
     std::unordered_map< OString, OString >::const_iterator aI = rWrapper.m_aLocalizedToCanonical.find(sFamily);
     if (aI != rWrapper.m_aLocalizedToCanonical.end())
@@ -1111,23 +1207,19 @@ std::unique_ptr<FontConfigFontOptions> PrintFontManager::getFontOptions(const Fa
     if( !sFamily.isEmpty() )
         FcPatternAddString(pPattern, FC_FAMILY, reinterpret_cast<FcChar8 const *>(sFamily.getStr()));
 
-    addtopattern(pPattern, rInfo.m_eItalic, rInfo.m_eWeight, rInfo.m_eWidth, rInfo.m_ePitch);
+    // TODO: ePitch argument of always PITCH_DONTKNOW is suspicious
+    addtopattern(pPattern, aKey.m_eItalic, aKey.m_eWeight, aKey.m_eWidth, PITCH_DONTKNOW);
     FcPatternAddDouble(pPattern, FC_PIXEL_SIZE, nSize);
 
-    int hintstyle = FC_HINT_FULL;
-
     FcConfigSubstitute(pConfig, pPattern, FcMatchPattern);
     FontConfigFontOptions::cairo_font_options_substitute(pPattern);
     FcDefaultSubstitute(pPattern);
 
     FcResult eResult = FcResultNoMatch;
     FcFontSet* pFontSet = rWrapper.getFontSet();
-    FcPattern* pResult = FcFontSetMatch( pConfig, &pFontSet, 1, pPattern, &eResult );
-    if( pResult )
+    if (FcPattern* pResult = FcFontSetMatch(pConfig, &pFontSet, 1, pPattern, &eResult))
     {
-        (void) FcPatternGetInteger(pResult,
-            FC_HINT_STYLE, 0, &hintstyle);
-
+        rWrapper.m_aCachedFontOptions.cache(aKey, pResult);
         pOptions.reset(new FontConfigFontOptions(pResult));
     }
 
@@ -1137,6 +1229,12 @@ std::unique_ptr<FontConfigFontOptions> PrintFontManager::getFontOptions(const Fa
     return pOptions;
 }
 
+void PrintFontManager::clearFontOptionsCache()
+{
+    FontCfgWrapper& rWrapper = FontCfgWrapper::get();
+    rWrapper.m_aCachedFontOptions.clear();
+}
+
 void PrintFontManager::matchFont( FastPrintFontInfo& rInfo, const css::lang::Locale& rLocale )
 {
     FontCfgWrapper& rWrapper = FontCfgWrapper::get();
diff --git a/vcl/unx/generic/gdi/freetypetextrender.cxx b/vcl/unx/generic/gdi/freetypetextrender.cxx
index 0e6556b24588..5f28ebdb91fe 100644
--- a/vcl/unx/generic/gdi/freetypetextrender.cxx
+++ b/vcl/unx/generic/gdi/freetypetextrender.cxx
@@ -101,6 +101,7 @@ bool FreeTypeTextRenderImpl::AddTempDevFont( PhysicalFontCollection* pFontCollec
 void FreeTypeTextRenderImpl::ClearDevFontCache()
 {
     FreetypeManager::get().ClearFontCache();
+    psp::PrintFontManager::clearFontOptionsCache();
 }
 
 void FreeTypeTextRenderImpl::GetDevFontList( PhysicalFontCollection* pFontCollection )
diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
index 9e4a4d44974c..0abddcdd9c09 100644
--- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
@@ -473,16 +473,9 @@ FreetypeFont::FreetypeFont(FreetypeFontInstance& rFontInstance, const std::share
 
 namespace
 {
-    std::unique_ptr<FontConfigFontOptions> GetFCFontOptions( const FontAttributes& rFontAttributes, int nSize)
+    std::unique_ptr<FontConfigFontOptions> GetFCFontOptions(const FontAttributes& rFontAttributes, int nSize)
     {
-        psp::FastPrintFontInfo aInfo;
-
-        aInfo.m_aFamilyName = rFontAttributes.GetFamilyName();
-        aInfo.m_eItalic = rFontAttributes.GetItalic();
-        aInfo.m_eWeight = rFontAttributes.GetWeight();
-        aInfo.m_eWidth = rFontAttributes.GetWidthType();
-
-        return psp::PrintFontManager::getFontOptions(aInfo, nSize);
+        return psp::PrintFontManager::getFontOptions(rFontAttributes, nSize);
     }
 }
 


More information about the Libreoffice-commits mailing list