defer finding dialog parent until we need it
[LibreOffice.git] / include / basegfx / utils / systemdependentdata.hxx
blobb07ae267e66278cb8aa107c5ea43abfd76095ff1
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 #pragma once
12 #include <sal/types.h>
13 #include <basegfx/basegfxdllapi.h>
14 #include <memory>
15 #include <unordered_map>
17 namespace basegfx
19 class SystemDependentData;
20 typedef std::shared_ptr<SystemDependentData> SystemDependentData_SharedPtr;
21 typedef std::weak_ptr<SystemDependentData> SystemDependentData_WeakPtr;
23 class BASEGFX_DLLPUBLIC SystemDependentDataManager
25 private:
26 // noncopyable
27 SystemDependentDataManager(const SystemDependentDataManager&) = delete;
28 SystemDependentDataManager& operator=(const SystemDependentDataManager&) = delete;
30 public:
31 SystemDependentDataManager();
32 virtual ~SystemDependentDataManager();
34 // call from (and with) SystemDependentData objects when start/end/touch
35 // usage is needed
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,
47 SDDType_CairoSurface,
48 SDDType_ID2D1PathGeometry,
49 SDDType_ID2D1Bitmap,
50 SDDType_BitmapHelper,
51 SDDType_MaskHelper,
52 SDDType_CairoPath,
53 SDDType_ModifiedBitmapEx,
54 SDDType_GraphicsPath,
55 SDDType_GdiPlusBitmap
58 class BASEGFX_DLLPUBLIC SystemDependentData
60 private:
61 // noncopyable
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;
69 // Type identifier
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;
78 public:
79 SystemDependentData(
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
94 // mnCalculatedCycles
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
110 private:
111 // Possibility to hold System-Dependent B2DPolygon-Representations
112 std::unordered_map< SDD_Type, SystemDependentData_WeakPtr > maSystemDependentReferences;
114 // noncopyable
115 SystemDependentDataHolder(const SystemDependentDataHolder&) = delete;
116 SystemDependentDataHolder& operator=(const SystemDependentDataHolder&) = delete;
118 public:
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: */