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>
15 SystemDependentDataManager::SystemDependentDataManager()
19 SystemDependentDataManager::~SystemDependentDataManager()
22 } // namespace basegfx
26 SystemDependentData::SystemDependentData(
27 SystemDependentDataManager
& rSystemDependentDataManager
)
28 : mrSystemDependentDataManager(rSystemDependentDataManager
),
33 SystemDependentData::~SystemDependentData()
37 sal_uInt32
SystemDependentData::calculateCombinedHoldCyclesInSeconds() const
39 if(0 == mnCalculatedCycles
)
41 const sal_Int64
nBytes(estimateUsageInBytes());
43 // tdf#129845 as indicator for no need to buffer trivial data, stay at and
44 // return zero. As border, use 450 bytes. For polygons, this means to buffer
45 // starting with ca. 50 points (GDIPLUS uses 9 bytes per coordinate). For
46 // Bitmap data this means to more or less always buffer (as it was before).
47 // For the future, a more sophisticated differentiation may be added
50 const sal_uInt32 nSeconds
= 60; // HoldCyclesInSeconds
52 // default is Seconds (minimal is one)
53 sal_uInt32
nResult(0 == nSeconds
? 1 : nSeconds
);
57 // use sqrt to get some curved shape. With a default of 60s we get
58 // a single second at 3600 byte. To get close to 10mb, multiply by
59 // a corresponding scaling factor
60 const double fScaleToMB(3600.0 / (1024.0 * 1024.0 * 10.0));
62 // also use a multiplier to move the start point higher
63 const double fMultiplierSeconds(10.0);
66 nResult
= static_cast<sal_uInt32
>((fMultiplierSeconds
* nSeconds
) / sqrt(nBytes
* fScaleToMB
));
74 // maximal value is nSeconds
75 if(nResult
> nSeconds
)
81 // set locally (once, on-demand created, non-zero)
82 const_cast<SystemDependentData
*>(this)->mnCalculatedCycles
= nResult
;
86 return mnCalculatedCycles
;
89 sal_Int64
SystemDependentData::estimateUsageInBytes() const
91 // default implementation has no idea
94 } // namespace basegfx
98 SystemDependentDataHolder::SystemDependentDataHolder()
99 : maSystemDependentReferences()
103 SystemDependentDataHolder::~SystemDependentDataHolder()
105 for(const auto& candidate
: maSystemDependentReferences
)
107 basegfx::SystemDependentData_SharedPtr
aData(candidate
.second
.lock());
111 aData
->getSystemDependentDataManager().endUsage(aData
);
116 void SystemDependentDataHolder::addOrReplaceSystemDependentData(basegfx::SystemDependentData_SharedPtr
& rData
)
118 const size_t hash_code(typeid(*rData
).hash_code());
119 auto result(maSystemDependentReferences
.find(hash_code
));
121 if(result
!= maSystemDependentReferences
.end())
123 basegfx::SystemDependentData_SharedPtr
aData(result
->second
.lock());
127 aData
->getSystemDependentDataManager().endUsage(aData
);
130 maSystemDependentReferences
.erase(result
);
131 result
= maSystemDependentReferences
.end();
134 maSystemDependentReferences
[hash_code
] = rData
;
135 rData
->getSystemDependentDataManager().startUsage(rData
);
138 SystemDependentData_SharedPtr
SystemDependentDataHolder::getSystemDependentData(size_t hash_code
) const
140 basegfx::SystemDependentData_SharedPtr aRetval
;
141 auto result(maSystemDependentReferences
.find(hash_code
));
143 if(result
!= maSystemDependentReferences
.end())
145 aRetval
= result
->second
.lock();
149 aRetval
->getSystemDependentDataManager().touchUsage(aRetval
);
153 const_cast< SystemDependentDataHolder
* >(this)->maSystemDependentReferences
.erase(result
);
159 } // namespace basegfx
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */