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 #include <vcl/gfxlink.hxx>
21 
22 #include <memory>
23 #include <mutex>
24 #include <chrono>
25 #include <o3tl/sorted_vector.hxx>
26 
27 class ImpGraphic;
28 
29 namespace vcl::graphic
30 {
31 class Manager final
32 {
33 private:
34  std::mutex maMutex; // instead of SolarMutex because graphics can live past vcl main
36  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);
46  void loopGraphicsAndSwapOut(std::unique_lock<std::mutex>& rGuard);
47 
48  DECL_LINK(SwapOutTimerHandler, Timer*, void);
49 
50  static sal_Int64 getGraphicSizeBytes(const ImpGraphic* pImpGraphic);
51  void reduceGraphicMemory(std::unique_lock<std::mutex>& rGuard);
52 
53 public:
54  static Manager& get();
55 
56  void swappedIn(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes);
57  void swappedOut(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes);
58 
59  void changeExisting(const ImpGraphic* pImpGraphic, sal_Int64 nOldSize);
60  void unregisterGraphic(ImpGraphic* pImpGraphic);
61 
62  std::shared_ptr<ImpGraphic> copy(std::shared_ptr<ImpGraphic> const& pImpGraphic);
63  std::shared_ptr<ImpGraphic> newInstance();
64  std::shared_ptr<ImpGraphic> newInstance(const BitmapEx& rBitmapEx);
65  std::shared_ptr<ImpGraphic> newInstance(std::shared_ptr<GfxLink> const& rLink,
66  sal_Int32 nPageIndex = 0);
67  std::shared_ptr<ImpGraphic>
68  newInstance(const std::shared_ptr<VectorGraphicData>& rVectorGraphicDataPtr);
69  std::shared_ptr<ImpGraphic> newInstance(const Animation& rAnimation);
70  std::shared_ptr<ImpGraphic> newInstance(const GDIMetaFile& rMtf);
71  std::shared_ptr<ImpGraphic> newInstance(const GraphicExternalLink& rGraphicLink);
72 };
73 
74 } // end namespace vcl::graphic
75 
76 #endif // INCLUDED_VCL_INC_GRAPHIC_MANAGER_HXX
77 
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
o3tl::sorted_vector< ImpGraphic * > m_pImpGraphicList
Definition: Manager.hxx:35
std::mutex maMutex
Definition: Manager.hxx:34
static sal_Int64 getGraphicSizeBytes(const ImpGraphic *pImpGraphic)
Definition: Manager.cxx:151
void unregisterGraphic(ImpGraphic *pImpGraphic)
Definition: Manager.cxx:200
void registerGraphic(const std::shared_ptr< ImpGraphic > &rImpGraphic)
Definition: Manager.cxx:167
std::shared_ptr< ImpGraphic > copy(std::shared_ptr< ImpGraphic > const &pImpGraphic)
Definition: Manager.cxx:208
bool mbReducingGraphicMemory
Definition: Manager.hxx:38
void swappedIn(const ImpGraphic *pImpGraphic, sal_Int64 nSizeBytes)
Definition: Manager.cxx:266
void loopGraphicsAndSwapOut(std::unique_lock< std::mutex > &rGuard)
Definition: Manager.cxx:78
DECL_LINK(SwapOutTimerHandler, Timer *, void)
std::chrono::seconds mnAllowedIdleTime
Definition: Manager.hxx:36
sal_Int64 mnUsedSize
Definition: Manager.hxx:40
void reduceGraphicMemory(std::unique_lock< std::mutex > &rGuard)
Definition: Manager.cxx:115
std::shared_ptr< ImpGraphic > newInstance()
Definition: Manager.cxx:215
void changeExisting(const ImpGraphic *pImpGraphic, sal_Int64 nOldSize)
Definition: Manager.cxx:284
sal_Int64 mnMemoryLimit
Definition: Manager.hxx:39
Definition: timer.hxx:26
void swappedOut(const ImpGraphic *pImpGraphic, sal_Int64 nSizeBytes)
Definition: Manager.cxx:275