summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2018-10-31 12:28:58 +0100
committerCaolán McNamara <caolanm@redhat.com>2018-11-01 11:20:43 +0100
commit4a66d7f0dd40c54307b5f750723f68b53703b01a (patch)
tree711dd3efe189f093f82b896db41535ed88406ed2 /vcl
parentc86728655415ea507cb5f8d7f0588014db2d6098 (diff)
tdf#121030 invalidate referenced FontInstances
This sets the FreetypeFont pointer of the FreetypeFontInstances to nullptr when clearing the cache. And it changes the interface functions of SalLayoutGlyphs to some variant different from std::vector. I don't know if we should prefer the mutable or the const font instance. With mutable at least one can invalidate the font instance when checking the IsValid(), so we can get rid of our referenced font instance. Change-Id: I6070cfcb3c549dbad3383bd4ec2b05b30645b753 Reviewed-on: https://gerrit.libreoffice.org/62688 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/impglyphitem.hxx6
-rw-r--r--vcl/source/control/imp_listbox.cxx2
-rw-r--r--vcl/source/gdi/impglyphitem.cxx33
-rw-r--r--vcl/source/gdi/sallayout.cxx4
-rw-r--r--vcl/source/window/menu.cxx2
-rw-r--r--vcl/source/window/menuitemlist.cxx2
-rw-r--r--vcl/unx/generic/glyphs/glyphcache.cxx2
7 files changed, 42 insertions, 9 deletions
diff --git a/vcl/inc/impglyphitem.hxx b/vcl/inc/impglyphitem.hxx
index 4c7673ed2077..009be6cc2506 100644
--- a/vcl/inc/impglyphitem.hxx
+++ b/vcl/inc/impglyphitem.hxx
@@ -98,13 +98,15 @@ protected:
public:
virtual ~SalLayoutGlyphsImpl();
virtual SalLayoutGlyphsImpl* clone(SalLayoutGlyphs&) const = 0;
+ virtual bool IsValid() const = 0;
+ virtual void Invalidate() = 0;
};
class SalGenericLayoutGlyphsImpl : public SalLayoutGlyphsImpl
{
friend class GenericSalLayout;
- const rtl::Reference<LogicalFontInstance> m_rFontInstance;
+ mutable rtl::Reference<LogicalFontInstance> m_rFontInstance;
SalGenericLayoutGlyphsImpl(SalLayoutGlyphs& rGlyphs, LogicalFontInstance& rFontInstance)
: m_rFontInstance(&rFontInstance)
@@ -115,6 +117,8 @@ class SalGenericLayoutGlyphsImpl : public SalLayoutGlyphsImpl
public:
SalLayoutGlyphsImpl* clone(SalLayoutGlyphs& rGlyphs) const override;
LogicalFontInstance& GetFont() const { return *m_rFontInstance; }
+ bool IsValid() const override;
+ void Invalidate() override;
};
#endif // INCLUDED_VCL_IMPGLYPHITEM_HXX
diff --git a/vcl/source/control/imp_listbox.cxx b/vcl/source/control/imp_listbox.cxx
index 6570fb34c578..265a9589ff63 100644
--- a/vcl/source/control/imp_listbox.cxx
+++ b/vcl/source/control/imp_listbox.cxx
@@ -618,7 +618,7 @@ struct ImplEntryMetrics
SalLayoutGlyphs* ImplEntryType::GetTextGlyphs(OutputDevice* pOutputDevice)
{
- if (!maStrGlyphs.empty())
+ if (maStrGlyphs.IsValid())
// Use pre-calculated result.
return &maStrGlyphs;
diff --git a/vcl/source/gdi/impglyphitem.cxx b/vcl/source/gdi/impglyphitem.cxx
index 8955ea890a9f..d3aa10ebd1b3 100644
--- a/vcl/source/gdi/impglyphitem.cxx
+++ b/vcl/source/gdi/impglyphitem.cxx
@@ -19,6 +19,10 @@
#include <impglyphitem.hxx>
+#if (defined UNX && !defined MACOSX)
+#include <unx/freetype_glyphcache.hxx>
+#endif
+
SalLayoutGlyphs::SalLayoutGlyphs()
: m_pImpl(nullptr)
{
@@ -35,12 +39,12 @@ SalLayoutGlyphs& SalLayoutGlyphs::operator=(const SalLayoutGlyphs& rOther)
return *this;
}
-bool SalLayoutGlyphs::empty() const { return !m_pImpl || m_pImpl->empty(); }
+bool SalLayoutGlyphs::IsValid() const { return m_pImpl && m_pImpl->IsValid(); }
-void SalLayoutGlyphs::clear()
+void SalLayoutGlyphs::Invalidate()
{
if (m_pImpl)
- m_pImpl->clear();
+ m_pImpl->Invalidate();
}
SalLayoutGlyphsImpl::~SalLayoutGlyphsImpl() {}
@@ -52,4 +56,27 @@ SalLayoutGlyphsImpl* SalGenericLayoutGlyphsImpl::clone(SalLayoutGlyphs& rGlyphs)
return pNew;
}
+bool SalGenericLayoutGlyphsImpl::IsValid() const
+{
+ if (!m_rFontInstance.is())
+ return false;
+ if (empty())
+ return false;
+#if (defined UNX && !defined MACOSX)
+ const FreetypeFontInstance* pFFI = dynamic_cast<FreetypeFontInstance*>(m_rFontInstance.get());
+ if (pFFI && !pFFI->GetFreetypeFont())
+ {
+ m_rFontInstance.clear();
+ return false;
+ }
+#endif
+ return true;
+}
+
+void SalGenericLayoutGlyphsImpl::Invalidate()
+{
+ m_rFontInstance.clear();
+ clear();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/sallayout.cxx b/vcl/source/gdi/sallayout.cxx
index 68319505a3fc..4cbca56d9b70 100644
--- a/vcl/source/gdi/sallayout.cxx
+++ b/vcl/source/gdi/sallayout.cxx
@@ -704,7 +704,7 @@ DeviceCoordinate GenericSalLayout::FillDXArray( DeviceCoordinate* pCharWidths )
// the text width is the maximum logical extent of all glyphs
DeviceCoordinate GenericSalLayout::GetTextWidth() const
{
- if( m_GlyphItems.empty() )
+ if (!m_GlyphItems.IsValid())
return 0;
// initialize the extent
@@ -733,7 +733,7 @@ void GenericSalLayout::Justify( DeviceCoordinate nNewWidth )
if( !nOldWidth || nNewWidth==nOldWidth )
return;
- if(m_GlyphItems.empty())
+ if (!m_GlyphItems.IsValid())
{
return;
}
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index eef0138f36b3..c67d275c0e55 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -987,7 +987,7 @@ void Menu::SetItemText( sal_uInt16 nItemId, const OUString& rStr )
{
pData->aText = rStr;
// Clear layout for aText.
- pData->aTextGlyphs.clear();
+ pData->aTextGlyphs.Invalidate();
ImplSetMenuItemData( pData );
// update native menu
if( ImplGetSalMenu() && pData->pSalMenuItem )
diff --git a/vcl/source/window/menuitemlist.cxx b/vcl/source/window/menuitemlist.cxx
index c0496f1ee603..62127940e4e1 100644
--- a/vcl/source/window/menuitemlist.cxx
+++ b/vcl/source/window/menuitemlist.cxx
@@ -41,7 +41,7 @@ MenuItemData::~MenuItemData()
SalLayoutGlyphs* MenuItemData::GetTextGlyphs(OutputDevice* pOutputDevice)
{
- if (!aTextGlyphs.empty())
+ if (aTextGlyphs.IsValid())
// Use pre-calculated result.
return &aTextGlyphs;
diff --git a/vcl/unx/generic/glyphs/glyphcache.cxx b/vcl/unx/generic/glyphs/glyphcache.cxx
index 29e0d1ba65b6..b541fe1861fe 100644
--- a/vcl/unx/generic/glyphs/glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/glyphcache.cxx
@@ -46,6 +46,8 @@ GlyphCache::~GlyphCache()
void GlyphCache::ClearFontCache()
{
+ for (auto &aFontPair : maFontList)
+ static_cast<FreetypeFontInstance*>(aFontPair.first.get())->SetFreetypeFont(nullptr);
maFontList.clear();
mpCurrentGCFont = nullptr;
m_aFontInfoList.clear();