summaryrefslogtreecommitdiff
path: root/vcl/inc/graphic/Manager.hxx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-03-18 00:17:54 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-03-30 15:21:10 +0100
commit324f2e135427f2f24cf7eb9a4fab4aa903329ae5 (patch)
treebdcf04a1cd47b22a7612e903f9c68aef17c1dc41 /vcl/inc/graphic/Manager.hxx
parent174430d7a831eede078b6718d991b506d39180f1 (diff)
vcl: change (graphic) Manager into a general memory manager
Graphic memory manager was changes so that it can work with any object that implements a specific interface (MemoryManaged). With this it will be possible to use other objects (that take a lot of memory) to be managed by the manager. It is also a first step to move memory managin responsibilities away from Graphic and move it into the specific objects instead (BitmapEx, Animation and VectorGraphic). Change-Id: I7638bd89a1c9ece5c4bc95b506d2192492894ef3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164958 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/inc/graphic/Manager.hxx')
-rw-r--r--vcl/inc/graphic/Manager.hxx67
1 files changed, 26 insertions, 41 deletions
diff --git a/vcl/inc/graphic/Manager.hxx b/vcl/inc/graphic/Manager.hxx
index d239f6a8b01d..0a4ee3fbc84d 100644
--- a/vcl/inc/graphic/Manager.hxx
+++ b/vcl/inc/graphic/Manager.hxx
@@ -11,66 +11,51 @@
#include <sal/types.h>
#include <rtl/strbuf.hxx>
-#include <vcl/bitmapex.hxx>
-#include <vcl/animate/Animation.hxx>
-#include <vcl/vectorgraphicdata.hxx>
#include <vcl/timer.hxx>
-#include <vcl/GraphicExternalLink.hxx>
-#include <vcl/gfxlink.hxx>
#include <memory>
#include <mutex>
#include <chrono>
#include <o3tl/sorted_vector.hxx>
-class ImpGraphic;
-
namespace vcl::graphic
{
-class Manager final
+class MemoryManaged;
+
+class VCL_DLLPUBLIC MemoryManager final
{
private:
+ o3tl::sorted_vector<MemoryManaged*> maObjectList;
+ sal_Int64 mnTotalSize = 0;
std::mutex maMutex; // instead of SolarMutex because graphics can live past vcl main
- o3tl::sorted_vector<ImpGraphic*> m_pImpGraphicList;
- std::chrono::seconds mnAllowedIdleTime;
- bool mbSwapEnabled;
- bool mbReducingGraphicMemory;
- sal_Int64 mnMemoryLimit;
- sal_Int64 mnUsedSize;
- Timer maSwapOutTimer;
-
- Manager();
-
- void registerGraphic(const std::shared_ptr<ImpGraphic>& rImpGraphic);
- void loopGraphicsAndSwapOut(std::unique_lock<std::mutex>& rGuard, bool bDropAll);
- DECL_LINK(SwapOutTimerHandler, Timer*, void);
+ std::chrono::seconds mnAllowedIdleTime = std::chrono::seconds(1);
+ bool mbSwapEnabled = true;
+ bool mbReducingGraphicMemory = false;
+ sal_Int64 mnMemoryLimit = 10'000'000;
+ Timer maSwapOutTimer;
+ sal_Int32 mnTimeout = 1'000;
+ sal_Int64 mnSmallFrySize = 100'000;
- static sal_Int64 getGraphicSizeBytes(const ImpGraphic* pImpGraphic);
- void reduceGraphicMemory(std::unique_lock<std::mutex>& rGuard, bool bDropAll = false);
+ DECL_LINK(ReduceMemoryTimerHandler, Timer*, void);
public:
- static Manager& get();
-
- void dropCache();
- void dumpState(rtl::OStringBuffer& rState);
+ MemoryManager();
+ void registerObject(MemoryManaged* pObject);
+ void unregisterObject(MemoryManaged* pObject);
+ void changeExisting(MemoryManaged* pObject, sal_Int64 nNewSize);
- void swappedIn(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes);
- void swappedOut(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes);
+ void swappedIn(MemoryManaged* pObject, sal_Int64 nNewSize);
+ void swappedOut(MemoryManaged* pObject, sal_Int64 nNewSize);
- void changeExisting(const ImpGraphic* pImpGraphic, sal_Int64 nOldSize);
- void unregisterGraphic(ImpGraphic* pImpGraphic);
+ static MemoryManager& get();
+ o3tl::sorted_vector<MemoryManaged*> const& getManagedObjects() { return maObjectList; }
+ sal_Int64 getTotalSize() { return mnTotalSize; }
- std::shared_ptr<ImpGraphic> copy(std::shared_ptr<ImpGraphic> const& pImpGraphic);
- std::shared_ptr<ImpGraphic> newInstance();
- std::shared_ptr<ImpGraphic> newInstance(const BitmapEx& rBitmapEx);
- std::shared_ptr<ImpGraphic> newInstance(std::shared_ptr<GfxLink> const& rLink,
- sal_Int32 nPageIndex = 0);
- std::shared_ptr<ImpGraphic>
- newInstance(const std::shared_ptr<VectorGraphicData>& rVectorGraphicDataPtr);
- std::shared_ptr<ImpGraphic> newInstance(const Animation& rAnimation);
- std::shared_ptr<ImpGraphic> newInstance(const GDIMetaFile& rMtf);
- std::shared_ptr<ImpGraphic> newInstance(const GraphicExternalLink& rGraphicLink);
+ void reduceMemory(std::unique_lock<std::mutex>& rGuard, bool bDropAll = false);
+ void loopAndReduceMemory(std::unique_lock<std::mutex>& rGuard, bool bDropAll = false);
+ void reduceAllAndNow();
+ void dumpState(rtl::OStringBuffer& rState);
};
} // end namespace vcl::graphic