Kaydet (Commit) 8fdb3711 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

Add GlyphCache instance to GenericUnixSalData

This gets rid of some statics and drops some duplicate code:
- the X11 based GlyphCache => gone
- the svp version of the GlyphCache => gone
- the "normal" GlyphCache
- the PrintFontManager

And while at it move the implementation into its own file
gendata.cxx.

Change-Id: I9063139c9482f5f37285505f389cf5f32c02426b
Reviewed-on: https://gerrit.libreoffice.org/61454
Tested-by: Jenkins
Reviewed-by: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
üst ede39d78
......@@ -17641,7 +17641,6 @@ vcl/inc/unx/desktops.hxx
vcl/inc/unx/fc_fontoptions.hxx
vcl/inc/unx/fontmanager.hxx
vcl/inc/unx/freetype_glyphcache.hxx
vcl/inc/unx/gendata.hxx
vcl/inc/unx/gendisp.hxx
vcl/inc/unx/geninst.h
vcl/inc/unx/genprn.h
......@@ -17691,6 +17690,7 @@ vcl/inc/unx/wmadaptor.hxx
vcl/inc/unx/x11/x11gdiimpl.h
vcl/inc/unx/x11/x11sys.hxx
vcl/inc/unx/x11/xlimits.hxx
vcl/inc/unx/x11/xrender_peer.hxx
vcl/inc/unx/x11_cursors/ase_curs.h
vcl/inc/unx/x11_cursors/ase_mask.h
vcl/inc/unx/x11_cursors/asn_curs.h
......@@ -18319,7 +18319,6 @@ vcl/unx/generic/gdi/salvd.cxx
vcl/unx/generic/gdi/x11cairotextrender.cxx
vcl/unx/generic/gdi/x11cairotextrender.hxx
vcl/unx/generic/gdi/xrender_peer.cxx
vcl/unx/generic/gdi/xrender_peer.hxx
vcl/unx/generic/glyphs/freetype_glyphcache.cxx
vcl/unx/generic/glyphs/glyphcache.cxx
vcl/unx/generic/print/bitmap_gfx.cxx
......
......@@ -454,7 +454,7 @@ vcl_headless_code= \
vcl_headless_freetype_code=\
vcl/headless/svpprn \
vcl/headless/svptext \
vcl/headless/svpglyphcache \
vcl/unx/generic/app/gendata \
vcl/unx/generic/gdi/cairotextrender \
vcl/unx/generic/glyphs/freetype_glyphcache \
vcl/unx/generic/glyphs/glyphcache \
......
......@@ -92,7 +92,6 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_gen,\
vcl/unx/generic/dtrans/X11_transferable \
vcl/unx/generic/gdi/cairo_xlib_cairo \
vcl/unx/generic/gdi/x11cairotextrender \
vcl/unx/generic/gdi/gcach_xpeer \
vcl/unx/generic/gdi/gdiimpl \
vcl/unx/generic/gdi/openglx11cairotextrender \
vcl/unx/generic/gdi/salbmp \
......
......@@ -38,6 +38,7 @@
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/utils/systemdependentdata.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <unx/gendata.hxx>
#if ENABLE_CAIRO_CANVAS
# if defined CAIRO_VERSION && CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 10, 0)
......@@ -2109,4 +2110,11 @@ bool SvpSalGraphics::supportsOperation(OutDevSupportType eType) const
return false;
}
GlyphCache& SvpSalGraphics::getPlatformGlyphCache()
{
GenericUnixSalData* const pSalData(GetGenericUnixSalData());
assert(pSalData);
return *pSalData->GetGlyphCache();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <memory>
#include <sal/types.h>
#include <cassert>
#include <rtl/instance.hxx>
#include <unx/geninst.h>
#include <unx/glyphcache.hxx>
#include <headless/svpgdi.hxx>
namespace
{
struct GlyphCacheHolder
{
private:
std::unique_ptr<GlyphCache> m_pSvpGlyphCache;
GlyphCacheHolder(const GlyphCacheHolder&) = delete;
GlyphCacheHolder& operator=(const GlyphCacheHolder&) = delete;
public:
GlyphCacheHolder()
: m_pSvpGlyphCache( new GlyphCache )
{
}
GlyphCache& getGlyphCache()
{
return *m_pSvpGlyphCache;
}
};
struct theGlyphCacheHolder :
public rtl::Static<GlyphCacheHolder, theGlyphCacheHolder>
{};
}
GlyphCache& SvpSalGraphics::getPlatformGlyphCache()
{
return theGlyphCacheHolder::get().getGlyphCache();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -32,7 +32,6 @@ class QCursor;
class VCLPLUG_QT5_PUBLIC Qt5Data : public GenericUnixSalData
{
o3tl::enumarray<PointerStyle, std::unique_ptr<QCursor>> m_aCursors;
std::unique_ptr<GlyphCache> m_pGlyphCache;
public:
explicit Qt5Data(SalInstance* pInstance);
......
......@@ -16,59 +16,86 @@
#include <memory>
class GlyphCache;
class SalGenericDisplay;
namespace psp { class PrintFontManager; }
namespace psp
{
class PrintFontManager;
}
enum GenericUnixSalDataType { SAL_DATA_GTK, SAL_DATA_GTK3,
SAL_DATA_KDE4, SAL_DATA_KDE5,
SAL_DATA_UNX, SAL_DATA_SVP,
SAL_DATA_ANDROID, SAL_DATA_IOS,
SAL_DATA_HEADLESS, SAL_DATA_QT5 };
enum GenericUnixSalDataType
{
SAL_DATA_GTK,
SAL_DATA_GTK3,
SAL_DATA_KDE4,
SAL_DATA_KDE5,
SAL_DATA_UNX,
SAL_DATA_SVP,
SAL_DATA_ANDROID,
SAL_DATA_IOS,
SAL_DATA_HEADLESS,
SAL_DATA_QT5
};
class VCL_DLLPUBLIC GenericUnixSalData : public SalData
{
protected:
private:
GenericUnixSalDataType const m_eType;
SalGenericDisplay *m_pDisplay;
SalGenericDisplay* m_pDisplay;
// cached hostname to avoid slow lookup
OUString m_aHostname;
OUString m_aHostname;
// for transient storage of unicode strings eg. 'u123' by input methods
OUString m_aUnicodeEntry;
OUString m_aUnicodeEntry;
friend class psp::PrintFontManager;
std::unique_ptr<GlyphCache> m_pGlyphCache;
std::unique_ptr<psp::PrintFontManager> m_pPrintFontManager;
public:
GenericUnixSalData(GenericUnixSalDataType const t, SalInstance *const pInstance);
void InitGlyphCache();
void InitPrintFontManager();
public:
GenericUnixSalData(GenericUnixSalDataType const t, SalInstance* const pInstance);
virtual ~GenericUnixSalData() override;
virtual void Dispose() {}
SalGenericDisplay *GetDisplay() const { return m_pDisplay; }
void SetDisplay( SalGenericDisplay *pDisp ) { m_pDisplay = pDisp; }
SalGenericDisplay* GetDisplay() const { return m_pDisplay; }
void SetDisplay(SalGenericDisplay* pDisp) { m_pDisplay = pDisp; }
const OUString& GetHostname()
{
if (m_aHostname.isEmpty())
osl_getLocalHostname( &m_aHostname.pData );
osl_getLocalHostname(&m_aHostname.pData);
return m_aHostname;
}
OUString &GetUnicodeCommand()
OUString& GetUnicodeCommand() { return m_aUnicodeEntry; }
GenericUnixSalDataType GetType() const { return m_eType; }
GlyphCache* GetGlyphCache()
{
return m_aUnicodeEntry;
if (!m_pGlyphCache)
InitGlyphCache();
return m_pGlyphCache.get();
}
GenericUnixSalDataType GetType() const
psp::PrintFontManager* GetPrintFontManager()
{
return m_eType;
if (!m_pPrintFontManager)
InitPrintFontManager();
// PrintFontManager needs the GlyphCache
assert(m_pGlyphCache.get());
return m_pPrintFontManager.get();
}
// Mostly useful for remote protocol backends
virtual void ErrorTrapPush() = 0;
virtual bool ErrorTrapPop( bool bIgnoreError = true ) = 0; // true on error
virtual bool ErrorTrapPop(bool bIgnoreError = true) = 0; // true on error
};
inline GenericUnixSalData * GetGenericUnixSalData()
inline GenericUnixSalData* GetGenericUnixSalData()
{
return static_cast<GenericUnixSalData *>(ImplGetSVData()->mpSalData);
return static_cast<GenericUnixSalData*>(ImplGetSVData()->mpSalData);
}
#endif
......
......@@ -50,7 +50,7 @@ class SvpGcpHelper;
namespace basegfx { class B2DPolyPolygon; }
namespace vcl { struct FontCapabilities; }
class VCL_DLLPUBLIC GlyphCache
class VCL_DLLPUBLIC GlyphCache final
{
public:
explicit GlyphCache();
......
......@@ -17,8 +17,8 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_VCL_UNX_GENERIC_GDI_XRENDER_PEER_HXX
#define INCLUDED_VCL_UNX_GENERIC_GDI_XRENDER_PEER_HXX
#ifndef INCLUDED_VCL_UNX_X11_XRENDER_PEER_HXX
#define INCLUDED_VCL_UNX_X11_XRENDER_PEER_HXX
#include <X11/Xlib.h>
#include <X11/Xutil.h>
......@@ -161,6 +161,6 @@ inline XRenderColor GetXRenderColor( Color rColor, double fTransparency )
return aRetVal;
}
#endif // INCLUDED_VCL_UNX_GENERIC_GDI_XRENDER_PEER_HXX
#endif // INCLUDED_VCL_UNX_X11_XRENDER_PEER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -153,7 +153,6 @@
Qt5Data::Qt5Data(SalInstance* pInstance)
: GenericUnixSalData(SAL_DATA_QT5, pInstance)
, m_pGlyphCache(new GlyphCache())
{
ImplSVData* pSVData = ImplGetSVData();
......
......@@ -17,20 +17,29 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_VCL_UNX_GENERIC_GDI_GCACH_XPEER_HXX
#define INCLUDED_VCL_UNX_GENERIC_GDI_GCACH_XPEER_HXX
#include <unx/gendata.hxx>
#include <unx/fontmanager.hxx>
#include <unx/glyphcache.hxx>
class X11GlyphCache : public GlyphCache
GenericUnixSalData::GenericUnixSalData(GenericUnixSalDataType const t, SalInstance* const pInstance)
: m_eType(t)
, m_pDisplay(nullptr)
, m_pGlyphCache(new GlyphCache)
{
public:
explicit X11GlyphCache();
virtual ~X11GlyphCache() override;
static X11GlyphCache& GetInstance();
static void KillInstance();
};
m_pInstance = pInstance;
SetSalData(this);
}
#endif // INCLUDED_VCL_UNX_GENERIC_GDI_GCACH_XPEER_HXX
GenericUnixSalData::~GenericUnixSalData() {}
void GenericUnixSalData::InitGlyphCache() { m_pGlyphCache.reset(new GlyphCache); }
void GenericUnixSalData::InitPrintFontManager()
{
GetGlyphCache();
m_pPrintFontManager.reset(new psp::PrintFontManager);
m_pPrintFontManager->initialize();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -67,6 +67,8 @@
#include <unx/salobj.h>
#include <unx/sm.hxx>
#include <unx/wmadaptor.hxx>
#include <unx/x11/xrender_peer.hxx>
#include <unx/glyphcache.hxx>
#include <vcl/opengl/OpenGLHelper.hxx>
......@@ -322,7 +324,28 @@ void SalDisplay::doDestruct()
m_pWMAdaptor.reset();
X11SalBitmap::ImplDestroyCache();
X11SalGraphics::releaseGlyphPeer();
if (ImplGetSVData())
{
SalDisplay* pSalDisp = vcl_sal::getSalDisplay(pData);
Display* const pX11Disp = pSalDisp->GetDisplay();
int nMaxScreens = pSalDisp->GetXScreenCount();
XRenderPeer& rRenderPeer = XRenderPeer::GetInstance();
for (int i = 0; i < nMaxScreens; i++)
{
SalDisplay::RenderEntryMap& rMap = pSalDisp->GetRenderEntries(SalX11Screen(i));
for (auto const& elem : rMap)
{
if (elem.second.m_aPixmap)
::XFreePixmap(pX11Disp, elem.second.m_aPixmap);
if (elem.second.m_aPicture)
rRenderPeer.FreePicture(elem.second.m_aPicture);
}
rMap.clear();
}
}
GlyphCache::GetInstance().ClearFontCache();
if( IsDisplay() )
{
......
......@@ -111,30 +111,14 @@ PrintFontManager::PrintFont::PrintFont()
{
}
GenericUnixSalData::GenericUnixSalData(GenericUnixSalDataType const t, SalInstance *const pInstance)
: m_eType(t), m_pDisplay(nullptr)
{
m_pInstance = pInstance; SetSalData(this);
}
GenericUnixSalData::~GenericUnixSalData()
{
}
/*
* one instance only
*/
PrintFontManager& PrintFontManager::get()
{
GenericUnixSalData *const pSalData(GetGenericUnixSalData());
GenericUnixSalData* const pSalData(GetGenericUnixSalData());
assert(pSalData);
if (!pSalData->m_pPrintFontManager)
{
pSalData->m_pPrintFontManager.reset( new PrintFontManager );
pSalData->m_pPrintFontManager->initialize();
}
return *pSalData->m_pPrintFontManager;
return *pSalData->GetPrintFontManager();
}
/*
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <rtl/ustring.hxx>
#include <osl/module.h>
#include <osl/thread.h>
#include <unx/saldisp.hxx>
#include <unx/salgdi.h>
#include "gcach_xpeer.hxx"
#include "xrender_peer.hxx"
X11GlyphCache::~X11GlyphCache()
{
if( !ImplGetSVData() )
return;
//Why do this here, move into dtor/shutdown of display?
SalDisplay* pSalDisp = vcl_sal::getSalDisplay(GetGenericUnixSalData());
Display* const pX11Disp = pSalDisp->GetDisplay();
int nMaxScreens = pSalDisp->GetXScreenCount();
XRenderPeer& rRenderPeer = XRenderPeer::GetInstance();
for( int i = 0; i < nMaxScreens; i++ )
{
SalDisplay::RenderEntryMap& rMap = pSalDisp->GetRenderEntries( SalX11Screen (i) );
for (auto const& elem : rMap)
{
if( elem.second.m_aPixmap )
::XFreePixmap( pX11Disp, elem.second.m_aPixmap );
if( elem.second.m_aPicture )
rRenderPeer.FreePicture( elem.second.m_aPicture );
}
rMap.clear();
}
}
X11GlyphCache::X11GlyphCache()
{
}
namespace
{
struct GlyphCacheHolder
{
private:
std::unique_ptr<X11GlyphCache> m_pX11GlyphCache;
GlyphCacheHolder(const GlyphCacheHolder&) = delete;
GlyphCacheHolder& operator=(const GlyphCacheHolder&) = delete;
public:
GlyphCacheHolder()
: m_pX11GlyphCache(new X11GlyphCache)
{
}
void release()
{
m_pX11GlyphCache.reset();
}
X11GlyphCache& getGlyphCache()
{
return *m_pX11GlyphCache;
}
};
struct theGlyphCacheHolder :
public rtl::Static<GlyphCacheHolder, theGlyphCacheHolder>
{};
}
X11GlyphCache& X11GlyphCache::GetInstance()
{
return theGlyphCacheHolder::get().getGlyphCache();
}
void X11GlyphCache::KillInstance()
{
return theGlyphCacheHolder::get().release();
}
void X11SalGraphics::releaseGlyphPeer()
{
X11GlyphCache::KillInstance();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -36,7 +36,7 @@
#include <unx/salvd.h>
#include <unx/x11/xlimits.hxx>
#include <salframe.hxx>
#include "xrender_peer.hxx"
#include <unx/x11/xrender_peer.hxx>
#include <outdata.hxx>
......
......@@ -62,7 +62,7 @@
#include "openglx11cairotextrender.hxx"
#include <unx/printergfx.hxx>
#include "xrender_peer.hxx"
#include <unx/x11/xrender_peer.hxx>
#include "cairo_xlib_cairo.hxx"
#include <cairo-xlib.h>
......
......@@ -32,7 +32,7 @@
#include <unx/salvd.h>
#include <unx/x11/x11gdiimpl.h>
#include <unx/x11/xlimits.hxx>
#include "xrender_peer.hxx"
#include <unx/x11/xrender_peer.hxx>
#include <salframe.hxx>
#include <unx/printergfx.hxx>
......
......@@ -20,7 +20,7 @@
#include "x11cairotextrender.hxx"
#include <unx/saldisp.hxx>
#include <unx/salvd.h>
#include "gcach_xpeer.hxx"
#include <unx/glyphcache.hxx>
#include <X11/Xregion.h>
#include <cairo.h>
......@@ -31,7 +31,7 @@ X11CairoTextRender::X11CairoTextRender(X11SalGraphics& rParent)
GlyphCache& X11CairoTextRender::getPlatformGlyphCache()
{
return X11GlyphCache::GetInstance();
return GlyphCache::GetInstance();
}
cairo_t* X11CairoTextRender::getCairoContext()
......
......@@ -21,7 +21,7 @@
#include <unx/salunx.h>
#include <unx/saldisp.hxx>
#include "xrender_peer.hxx"
#include <unx/x11/xrender_peer.hxx>
XRenderPeer::XRenderPeer()
: mpDisplay( vcl_sal::getSalDisplay(GetGenericUnixSalData())->GetDisplay() )
......
......@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <math.h>
#include <unx/freetype_glyphcache.hxx>
#include <unx/gendata.hxx>
#include <vcl/svapp.hxx>
#include <vcl/bitmap.hxx>
......@@ -30,8 +31,6 @@
#include <osl/file.hxx>
#include <sal/log.hxx>
static GlyphCache* pInstance = nullptr;
GlyphCache::GlyphCache()
: mnBytesUsed(sizeof(GlyphCache)),
mnLruIndex(0),
......@@ -39,8 +38,6 @@ GlyphCache::GlyphCache()
mpCurrentGCFont(nullptr)
, m_nMaxFontId(0)
{
pInstance = this;
InitFreetype();
}
......@@ -159,7 +156,9 @@ bool GlyphCache::IFSD_Equal::operator()(const rtl::Reference<LogicalFontInstance
GlyphCache& GlyphCache::GetInstance()
{
return *pInstance;
GenericUnixSalData* const pSalData(GetGenericUnixSalData());
assert(pSalData);
return *pSalData->GetGlyphCache();
}
FreetypeFont* GlyphCache::CacheFont(LogicalFontInstance* pFontInstance)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment