LibreOffice Module basegfx (master) 1
systemdependentdata.cxx
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
11#include <config_fuzzers.h>
12#include <math.h>
13
14namespace basegfx
15{
17 {
18 }
19
21 {
22 }
23} // namespace basegfx
24
25namespace basegfx
26{
28 SystemDependentDataManager& rSystemDependentDataManager)
29 : mrSystemDependentDataManager(rSystemDependentDataManager),
30 mnCalculatedCycles(0)
31 {
32 }
33
35 {
36 }
37
39 {
40#if ENABLE_FUZZERS
41 return 0;
42#endif
43
44 if(0 == mnCalculatedCycles)
45 {
46 const sal_Int64 nBytes(estimateUsageInBytes());
47
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
53 if(nBytes > 450)
54 {
55 // HoldCyclesInSeconds
56 const sal_uInt32 nSeconds = 60;
57
58 // default is Seconds (minimal is one)
59 sal_uInt32 nResult(0 == nSeconds ? 1 : nSeconds);
60
61 if(0 != nBytes)
62 {
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));
67
68 // also use a multiplier to move the start point higher
69 const double fMultiplierSeconds(10.0);
70
71 // calculate
72 nResult = static_cast<sal_uInt32>((fMultiplierSeconds * nSeconds) / sqrt(nBytes * fScaleToMB));
73
74 // minimal value is 1
75 if(nResult < 1)
76 {
77 nResult = 1;
78 }
79
80 // maximal value is nSeconds
81 if(nResult > nSeconds)
82 {
83 nResult = nSeconds;
84 }
85 }
86
87 // set locally (once, on-demand created, non-zero)
88 const_cast<SystemDependentData*>(this)->mnCalculatedCycles = nResult;
89 }
90 }
91
92 return mnCalculatedCycles;
93 }
94
96 {
97 // default implementation has no idea
98 return 0;
99 }
100} // namespace basegfx
101
102namespace basegfx
103{
105 {
106 }
107
109 {
110 for(const auto& candidate : maSystemDependentReferences)
111 {
112 basegfx::SystemDependentData_SharedPtr aData(candidate.second.lock());
113
114 if(aData)
115 {
116 aData->getSystemDependentDataManager().endUsage(aData);
117 }
118 }
119 }
120
122 {
123 const size_t hash_code(typeid(*rData).hash_code());
124 auto result(maSystemDependentReferences.find(hash_code));
125
127 {
129
130 if(aData)
131 {
132 aData->getSystemDependentDataManager().endUsage(aData);
133 }
134
137 }
138
139 maSystemDependentReferences[hash_code] = rData;
140 rData->getSystemDependentDataManager().startUsage(rData);
141 }
142
144 {
146 auto result(maSystemDependentReferences.find(hash_code));
147
149 {
150 aRetval = result->second.lock();
151
152 if(aRetval)
153 {
154 aRetval->getSystemDependentDataManager().touchUsage(aRetval);
155 }
156 else
157 {
159 }
160 }
161
162 return aRetval;
163 }
164} // namespace basegfx
165
166/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::map< size_t, SystemDependentData_WeakPtr > maSystemDependentReferences
void addOrReplaceSystemDependentData(SystemDependentData_SharedPtr &rData)
SystemDependentData_SharedPtr getSystemDependentData(size_t hash_code) const
virtual sal_Int64 estimateUsageInBytes() const
sal_uInt32 calculateCombinedHoldCyclesInSeconds() const
SystemDependentData(const SystemDependentData &)=delete
constexpr OUStringLiteral aData
std::shared_ptr< SystemDependentData > SystemDependentData_SharedPtr
Definition: b2dpolygon.hxx:41
Any result