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 <unordered_set>
25 
26 class ImpGraphic;
27 
28 namespace vcl
29 {
30 namespace graphic
31 {
32 class Manager final
33 {
34 private:
35  std::recursive_mutex maMutex; // instead of SolarMutex because graphics can live past vcl main
36  std::unordered_set<ImpGraphic*> m_pImpGraphicList;
37  std::chrono::seconds mnAllowedIdleTime;
39  sal_Int64 mnMemoryLimit;
40  sal_Int64 mnUsedSize;
42 
43  Manager();
44 
45  void registerGraphic(const std::shared_ptr<ImpGraphic>& rImpGraphic, OUString const& rsContext);
46 
47  DECL_LINK(SwapOutTimerHandler, Timer*, void);
48 
49  static sal_Int64 getGraphicSizeBytes(const ImpGraphic* pImpGraphic);
50 
51 public:
52  static Manager& get();
53 
54  void swappedIn(const ImpGraphic* pImpGraphic);
55  void swappedOut(const ImpGraphic* pImpGraphic);
56 
57  void reduceGraphicMemory();
58  void changeExisting(const ImpGraphic* pImpGraphic, sal_Int64 nOldSize);
59  void unregisterGraphic(ImpGraphic* pImpGraphic);
60 
61  std::shared_ptr<ImpGraphic> copy(std::shared_ptr<ImpGraphic> const& pImpGraphic);
62  std::shared_ptr<ImpGraphic> newInstance();
63  std::shared_ptr<ImpGraphic> newInstance(const Bitmap& rBitmap);
64  std::shared_ptr<ImpGraphic> newInstance(const BitmapEx& rBitmapEx);
65  std::shared_ptr<ImpGraphic> newInstance(const VectorGraphicDataPtr& rVectorGraphicDataPtr);
66  std::shared_ptr<ImpGraphic> newInstance(const Animation& rAnimation);
67  std::shared_ptr<ImpGraphic> newInstance(const GDIMetaFile& rMtf);
68  std::shared_ptr<ImpGraphic> newInstance(const GraphicExternalLink& rGraphicLink);
69 };
70 }
71 } // end namespace vcl::graphic
72 
73 #endif // INCLUDED_VCL_INC_GRAPHIC_MANAGER_HXX
74 
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unordered_set< ImpGraphic * > m_pImpGraphicList
Definition: Manager.hxx:36
static sal_Int64 getGraphicSizeBytes(const ImpGraphic *pImpGraphic)
Definition: Manager.cxx:108
void unregisterGraphic(ImpGraphic *pImpGraphic)
Definition: Manager.cxx:156
void reduceGraphicMemory()
Definition: Manager.cxx:80
std::shared_ptr< ImpGraphic > copy(std::shared_ptr< ImpGraphic > const &pImpGraphic)
Definition: Manager.cxx:164
std::recursive_mutex maMutex
Definition: Manager.hxx:35
DECL_LINK(SwapOutTimerHandler, Timer *, void)
std::chrono::seconds mnAllowedIdleTime
Definition: Manager.hxx:37
sal_Int64 mnUsedSize
Definition: Manager.hxx:40
std::shared_ptr< ImpGraphic > newInstance()
Definition: Manager.cxx:171
void changeExisting(const ImpGraphic *pImpGraphic, sal_Int64 nOldSize)
Definition: Manager.cxx:234
void registerGraphic(const std::shared_ptr< ImpGraphic > &rImpGraphic, OUString const &rsContext)
Definition: Manager.cxx:124
std::shared_ptr< VectorGraphicData > VectorGraphicDataPtr
void swappedIn(const ImpGraphic *pImpGraphic)
Definition: Manager.cxx:220
void swappedOut(const ImpGraphic *pImpGraphic)
Definition: Manager.cxx:227
sal_Int64 mnMemoryLimit
Definition: Manager.hxx:39
Definition: timer.hxx:26