LibreOffice Module vcl (master) 1
Manager.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#ifndef INCLUDED_VCL_INC_GRAPHIC_MANAGER_HXX
11#define INCLUDED_VCL_INC_GRAPHIC_MANAGER_HXX
12
13#include <sal/types.h>
14#include <rtl/strbuf.hxx>
15#include <rtl/ustring.hxx>
16#include <vcl/bitmapex.hxx>
19#include <vcl/timer.hxx>
21#include <vcl/gfxlink.hxx>
22
23#include <memory>
24#include <mutex>
25#include <chrono>
27
28class ImpGraphic;
29
30namespace vcl::graphic
31{
32class Manager final
33{
34private:
35 std::mutex maMutex; // instead of SolarMutex because graphics can live past vcl main
37 std::chrono::seconds mnAllowedIdleTime;
40 sal_Int64 mnMemoryLimit;
41 sal_Int64 mnUsedSize;
43
44 Manager();
45
46 void registerGraphic(const std::shared_ptr<ImpGraphic>& rImpGraphic);
47 void loopGraphicsAndSwapOut(std::unique_lock<std::mutex>& rGuard, bool bDropAll);
48
49 DECL_LINK(SwapOutTimerHandler, Timer*, void);
50
51 static sal_Int64 getGraphicSizeBytes(const ImpGraphic* pImpGraphic);
52 void reduceGraphicMemory(std::unique_lock<std::mutex>& rGuard, bool bDropAll = false);
53
54public:
55 static Manager& get();
56
57 void dropCache();
58 void dumpState(rtl::OStringBuffer& rState);
59
60 void swappedIn(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes);
61 void swappedOut(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes);
62
63 void changeExisting(const ImpGraphic* pImpGraphic, sal_Int64 nOldSize);
64 void unregisterGraphic(ImpGraphic* pImpGraphic);
65
66 std::shared_ptr<ImpGraphic> copy(std::shared_ptr<ImpGraphic> const& pImpGraphic);
67 std::shared_ptr<ImpGraphic> newInstance();
68 std::shared_ptr<ImpGraphic> newInstance(const BitmapEx& rBitmapEx);
69 std::shared_ptr<ImpGraphic> newInstance(std::shared_ptr<GfxLink> const& rLink,
70 sal_Int32 nPageIndex = 0);
71 std::shared_ptr<ImpGraphic>
72 newInstance(const std::shared_ptr<VectorGraphicData>& rVectorGraphicDataPtr);
73 std::shared_ptr<ImpGraphic> newInstance(const Animation& rAnimation);
74 std::shared_ptr<ImpGraphic> newInstance(const GDIMetaFile& rMtf);
75 std::shared_ptr<ImpGraphic> newInstance(const GraphicExternalLink& rGraphicLink);
76};
77
78} // end namespace vcl::graphic
79
80#endif // INCLUDED_VCL_INC_GRAPHIC_MANAGER_HXX
81
82/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: timer.hxx:27
void changeExisting(const ImpGraphic *pImpGraphic, sal_Int64 nOldSize)
Definition: Manager.cxx:308
sal_Int64 mnMemoryLimit
Definition: Manager.hxx:40
o3tl::sorted_vector< ImpGraphic * > m_pImpGraphicList
Definition: Manager.hxx:36
std::shared_ptr< ImpGraphic > newInstance()
Definition: Manager.cxx:239
std::shared_ptr< ImpGraphic > copy(std::shared_ptr< ImpGraphic > const &pImpGraphic)
Definition: Manager.cxx:232
bool mbReducingGraphicMemory
Definition: Manager.hxx:39
DECL_LINK(SwapOutTimerHandler, Timer *, void)
static Manager & get()
Definition: Manager.cxx:54
void reduceGraphicMemory(std::unique_lock< std::mutex > &rGuard, bool bDropAll=false)
Definition: Manager.cxx:115
void loopGraphicsAndSwapOut(std::unique_lock< std::mutex > &rGuard, bool bDropAll)
Definition: Manager.cxx:78
void swappedOut(const ImpGraphic *pImpGraphic, sal_Int64 nSizeBytes)
Definition: Manager.cxx:299
static sal_Int64 getGraphicSizeBytes(const ImpGraphic *pImpGraphic)
Definition: Manager.cxx:175
void registerGraphic(const std::shared_ptr< ImpGraphic > &rImpGraphic)
Definition: Manager.cxx:191
void unregisterGraphic(ImpGraphic *pImpGraphic)
Definition: Manager.cxx:224
void swappedIn(const ImpGraphic *pImpGraphic, sal_Int64 nSizeBytes)
Definition: Manager.cxx:290
void dumpState(rtl::OStringBuffer &rState)
Definition: Manager.cxx:159
sal_Int64 mnUsedSize
Definition: Manager.hxx:41
std::mutex maMutex
Definition: Manager.hxx:35
std::chrono::seconds mnAllowedIdleTime
Definition: Manager.hxx:37