1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
12 #include <sal/types.h>
13 #include <basegfx/basegfxdllapi.h>
15 #include <unordered_map>
19 class SystemDependentData
;
20 typedef std::shared_ptr
<SystemDependentData
> SystemDependentData_SharedPtr
;
21 typedef std::weak_ptr
<SystemDependentData
> SystemDependentData_WeakPtr
;
23 class BASEGFX_DLLPUBLIC SystemDependentDataManager
27 SystemDependentDataManager(const SystemDependentDataManager
&) = delete;
28 SystemDependentDataManager
& operator=(const SystemDependentDataManager
&) = delete;
31 SystemDependentDataManager();
32 virtual ~SystemDependentDataManager();
34 // call from (and with) SystemDependentData objects when start/end/touch
36 virtual void startUsage(basegfx::SystemDependentData_SharedPtr
& rData
) = 0;
37 virtual void endUsage(basegfx::SystemDependentData_SharedPtr
& rData
) = 0;
38 virtual void touchUsage(basegfx::SystemDependentData_SharedPtr
& rData
) = 0;
40 // flush all buffered data (e.g. cleanup/shutdown)
41 virtual void flushAll() = 0;
44 // (S)ystem(D)ependent(D)ata_Type
45 enum class BASEGFX_DLLPUBLIC SDD_Type
: sal_uInt16
{
46 SDDType_CairoPathGeometry
,
48 SDDType_ID2D1PathGeometry
,
53 SDDType_ModifiedBitmapEx
,
58 class BASEGFX_DLLPUBLIC SystemDependentData
62 SystemDependentData(const SystemDependentData
&) = delete;
63 SystemDependentData
& operator=(const SystemDependentData
&) = delete;
65 // reference to a SystemDependentDataManager, probably
66 // a single, globally used one, but not necessarily
67 SystemDependentDataManager
& mrSystemDependentDataManager
;
70 SDD_Type maSystemDependentDataType
;
72 // Buffered CalculatedCycles, result of estimations using
73 // getHoldCyclesInSeconds and estimateUsageInBytes, executed
74 // using getHoldCyclesInSeconds. StartValue is 0 to detect
75 // not-yet-calculated state
76 sal_uInt32 mnCalculatedCycles
;
80 SystemDependentDataManager
& rSystemDependentDataManager
,
81 SDD_Type aSystemDependentDataType
);
82 virtual ~SystemDependentData();
84 // allow access to call startUsage/endUsage/touchUsage
85 // using getSystemDependentDataManager()
86 SystemDependentDataManager
& getSystemDependentDataManager() { return mrSystemDependentDataManager
; }
88 // read access to SDD_Type
89 SDD_Type
getSystemDependentDataType() const { return maSystemDependentDataType
; }
91 // Calculate HoldCyclesInSeconds based on using
92 // getHoldCyclesInSeconds and estimateUsageInBytes, the
93 // result is created once on-demand and buffered in
95 sal_uInt32
calculateCombinedHoldCyclesInSeconds() const;
97 // Allow read access to the calculated cycles in seconds, this
98 // can be e.g. used to determine if this instance got added
99 sal_uInt32
getCombinedHoldCyclesInSeconds() const { return mnCalculatedCycles
; }
101 // Size estimation of the entry in bytes - does not have to
102 // be used, but should be. Default returns zero what
103 // means there is no size estimation available. Override to
104 // offer useful data if you want to have better caching.
105 virtual sal_Int64
estimateUsageInBytes() const;
108 class BASEGFX_DLLPUBLIC SystemDependentDataHolder
111 // Possibility to hold System-Dependent B2DPolygon-Representations
112 std::unordered_map
< SDD_Type
, SystemDependentData_WeakPtr
> maSystemDependentReferences
;
115 SystemDependentDataHolder(const SystemDependentDataHolder
&) = delete;
116 SystemDependentDataHolder
& operator=(const SystemDependentDataHolder
&) = delete;
119 SystemDependentDataHolder();
120 virtual ~SystemDependentDataHolder();
122 void addOrReplaceSystemDependentData(SystemDependentData_SharedPtr
& rData
);
123 SystemDependentData_SharedPtr
getSystemDependentData(SDD_Type aType
) const;
125 } // end of namespace basegfx
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */