Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / inc / graphic / Manager.hxx
blob65e92146491cc7a60b2664ebff8da9f8ea73b41b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #ifndef INCLUDED_VCL_INC_GRAPHIC_MANAGER_HXX
11 #define INCLUDED_VCL_INC_GRAPHIC_MANAGER_HXX
13 #include <sal/types.h>
14 #include <rtl/strbuf.hxx>
15 #include <vcl/bitmapex.hxx>
16 #include <vcl/animate/Animation.hxx>
17 #include <vcl/vectorgraphicdata.hxx>
18 #include <vcl/timer.hxx>
19 #include <vcl/GraphicExternalLink.hxx>
20 #include <vcl/gfxlink.hxx>
22 #include <memory>
23 #include <mutex>
24 #include <chrono>
25 #include <o3tl/sorted_vector.hxx>
27 class ImpGraphic;
29 namespace vcl::graphic
31 class Manager final
33 private:
34 std::mutex maMutex; // instead of SolarMutex because graphics can live past vcl main
35 o3tl::sorted_vector<ImpGraphic*> m_pImpGraphicList;
36 std::chrono::seconds mnAllowedIdleTime;
37 bool mbSwapEnabled;
38 bool mbReducingGraphicMemory;
39 sal_Int64 mnMemoryLimit;
40 sal_Int64 mnUsedSize;
41 Timer maSwapOutTimer;
43 Manager();
45 void registerGraphic(const std::shared_ptr<ImpGraphic>& rImpGraphic);
46 void loopGraphicsAndSwapOut(std::unique_lock<std::mutex>& rGuard, bool bDropAll);
48 DECL_LINK(SwapOutTimerHandler, Timer*, void);
50 static sal_Int64 getGraphicSizeBytes(const ImpGraphic* pImpGraphic);
51 void reduceGraphicMemory(std::unique_lock<std::mutex>& rGuard, bool bDropAll = false);
53 public:
54 static Manager& get();
56 void dropCache();
57 void dumpState(rtl::OStringBuffer& rState);
59 void swappedIn(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes);
60 void swappedOut(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes);
62 void changeExisting(const ImpGraphic* pImpGraphic, sal_Int64 nOldSize);
63 void unregisterGraphic(ImpGraphic* pImpGraphic);
65 std::shared_ptr<ImpGraphic> copy(std::shared_ptr<ImpGraphic> const& pImpGraphic);
66 std::shared_ptr<ImpGraphic> newInstance();
67 std::shared_ptr<ImpGraphic> newInstance(const BitmapEx& rBitmapEx);
68 std::shared_ptr<ImpGraphic> newInstance(std::shared_ptr<GfxLink> const& rLink,
69 sal_Int32 nPageIndex = 0);
70 std::shared_ptr<ImpGraphic>
71 newInstance(const std::shared_ptr<VectorGraphicData>& rVectorGraphicDataPtr);
72 std::shared_ptr<ImpGraphic> newInstance(const Animation& rAnimation);
73 std::shared_ptr<ImpGraphic> newInstance(const GDIMetaFile& rMtf);
74 std::shared_ptr<ImpGraphic> newInstance(const GraphicExternalLink& rGraphicLink);
77 } // end namespace vcl::graphic
79 #endif // INCLUDED_VCL_INC_GRAPHIC_MANAGER_HXX
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */