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/ustring.hxx>
15 #include <vcl/bitmapex.hxx>
18 #include <vcl/timer.hxx>
20 
21 #include <memory>
22 #include <mutex>
23 #include <chrono>
24 #include <o3tl/sorted_vector.hxx>
25 
26 class ImpGraphic;
27 
28 namespace vcl::graphic
29 {
30 class Manager final
31 {
32 private:
33  std::recursive_mutex maMutex; // instead of SolarMutex because graphics can live past vcl main
35  std::chrono::seconds mnAllowedIdleTime;
37  sal_Int64 mnMemoryLimit;
38  sal_Int64 mnUsedSize;
40 
41  Manager();
42 
43  void registerGraphic(const std::shared_ptr<ImpGraphic>& rImpGraphic, OUString const& rsContext);
44 
45  DECL_LINK(SwapOutTimerHandler, Timer*, void);
46 
47  static sal_Int64 getGraphicSizeBytes(const ImpGraphic* pImpGraphic);
48 
49 public:
50  static Manager& get();
51 
52  void swappedIn(const ImpGraphic* pImpGraphic);
53  void swappedOut(const ImpGraphic* pImpGraphic);
54 
55  void reduceGraphicMemory();
56  void changeExisting(const ImpGraphic* pImpGraphic, sal_Int64 nOldSize);
57  void unregisterGraphic(ImpGraphic* pImpGraphic);
58 
59  std::shared_ptr<ImpGraphic> copy(std::shared_ptr<ImpGraphic> const& pImpGraphic);
60  std::shared_ptr<ImpGraphic> newInstance();
61  std::shared_ptr<ImpGraphic> newInstance(const BitmapEx& rBitmapEx);
62  std::shared_ptr<ImpGraphic>
63  newInstance(const std::shared_ptr<VectorGraphicData>& rVectorGraphicDataPtr);
64  std::shared_ptr<ImpGraphic> newInstance(const Animation& rAnimation);
65  std::shared_ptr<ImpGraphic> newInstance(const GDIMetaFile& rMtf);
66  std::shared_ptr<ImpGraphic> newInstance(const GraphicExternalLink& rGraphicLink);
67 };
68 
69 } // end namespace vcl::graphic
70 
71 #endif // INCLUDED_VCL_INC_GRAPHIC_MANAGER_HXX
72 
73 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
o3tl::sorted_vector< ImpGraphic * > m_pImpGraphicList
Definition: Manager.hxx:34
static sal_Int64 getGraphicSizeBytes(const ImpGraphic *pImpGraphic)
Definition: Manager.cxx:111
void unregisterGraphic(ImpGraphic *pImpGraphic)
Definition: Manager.cxx:159
void reduceGraphicMemory()
Definition: Manager.cxx:78
std::shared_ptr< ImpGraphic > copy(std::shared_ptr< ImpGraphic > const &pImpGraphic)
Definition: Manager.cxx:167
std::recursive_mutex maMutex
Definition: Manager.hxx:33
DECL_LINK(SwapOutTimerHandler, Timer *, void)
std::chrono::seconds mnAllowedIdleTime
Definition: Manager.hxx:35
sal_Int64 mnUsedSize
Definition: Manager.hxx:38
std::shared_ptr< ImpGraphic > newInstance()
Definition: Manager.cxx:174
void changeExisting(const ImpGraphic *pImpGraphic, sal_Int64 nOldSize)
Definition: Manager.cxx:231
void registerGraphic(const std::shared_ptr< ImpGraphic > &rImpGraphic, OUString const &rsContext)
Definition: Manager.cxx:127
void swappedIn(const ImpGraphic *pImpGraphic)
Definition: Manager.cxx:217
void swappedOut(const ImpGraphic *pImpGraphic)
Definition: Manager.cxx:224
sal_Int64 mnMemoryLimit
Definition: Manager.hxx:37
Definition: timer.hxx:26