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/.
10 #include <basegfx/utils/systemdependentdata.hxx>
11 #include <config_fuzzers.h>
16 SystemDependentDataManager::SystemDependentDataManager()
20 SystemDependentDataManager::~SystemDependentDataManager()
23 } // namespace basegfx
27 SystemDependentData::SystemDependentData(
28 SystemDependentDataManager
& rSystemDependentDataManager
)
29 : mrSystemDependentDataManager(rSystemDependentDataManager
),
34 SystemDependentData::~SystemDependentData()
38 sal_uInt32
SystemDependentData::calculateCombinedHoldCyclesInSeconds() const
44 if(0 == mnCalculatedCycles
)
46 const sal_Int64
nBytes(estimateUsageInBytes());
48 // tdf#129845 as indicator for no need to buffer trivial data, stay at and
49 // return zero. As border, use 450 bytes. For polygons, this means to buffer
50 // starting with ca. 50 points (GDIPLUS uses 9 bytes per coordinate). For
51 // Bitmap data this means to more or less always buffer (as it was before).
52 // For the future, a more sophisticated differentiation may be added
55 // HoldCyclesInSeconds
56 const sal_uInt32 nSeconds
= 60;
58 // default is Seconds (minimal is one)
59 sal_uInt32
nResult(0 == nSeconds
? 1 : nSeconds
);
63 // use sqrt to get some curved shape. With a default of 60s we get
64 // a single second at 3600 byte. To get close to 10mb, multiply by
65 // a corresponding scaling factor
66 const double fScaleToMB(3600.0 / (1024.0 * 1024.0 * 10.0));
68 // also use a multiplier to move the start point higher
69 const double fMultiplierSeconds(10.0);
72 nResult
= static_cast<sal_uInt32
>((fMultiplierSeconds
* nSeconds
) / sqrt(nBytes
* fScaleToMB
));
80 // maximal value is nSeconds
81 if(nResult
> nSeconds
)
87 // set locally (once, on-demand created, non-zero)
88 const_cast<SystemDependentData
*>(this)->mnCalculatedCycles
= nResult
;
92 return mnCalculatedCycles
;
95 sal_Int64
SystemDependentData::estimateUsageInBytes() const
97 // default implementation has no idea
100 } // namespace basegfx
104 SystemDependentDataHolder::SystemDependentDataHolder()
108 SystemDependentDataHolder::~SystemDependentDataHolder()
110 for(const auto& candidate
: maSystemDependentReferences
)
112 basegfx::SystemDependentData_SharedPtr
aData(candidate
.second
.lock());
116 aData
->getSystemDependentDataManager().endUsage(aData
);
121 void SystemDependentDataHolder::addOrReplaceSystemDependentData(basegfx::SystemDependentData_SharedPtr
& rData
)
123 const size_t hash_code(typeid(*rData
).hash_code());
124 auto result(maSystemDependentReferences
.find(hash_code
));
126 if(result
!= maSystemDependentReferences
.end())
128 basegfx::SystemDependentData_SharedPtr
aData(result
->second
.lock());
132 aData
->getSystemDependentDataManager().endUsage(aData
);
135 maSystemDependentReferences
.erase(result
);
136 result
= maSystemDependentReferences
.end();
139 maSystemDependentReferences
[hash_code
] = rData
;
140 rData
->getSystemDependentDataManager().startUsage(rData
);
143 SystemDependentData_SharedPtr
SystemDependentDataHolder::getSystemDependentData(size_t hash_code
) const
145 basegfx::SystemDependentData_SharedPtr aRetval
;
146 auto result(maSystemDependentReferences
.find(hash_code
));
148 if(result
!= maSystemDependentReferences
.end())
150 aRetval
= result
->second
.lock();
154 aRetval
->getSystemDependentDataManager().touchUsage(aRetval
);
158 const_cast< SystemDependentDataHolder
* >(this)->maSystemDependentReferences
.erase(result
);
164 } // namespace basegfx
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */