Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/basegfx/utils/systemdependentdata.hxx
Line
Count
Source
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
10
#pragma once
11
12
#include <sal/types.h>
13
#include <basegfx/basegfxdllapi.h>
14
#include <memory>
15
#include <unordered_map>
16
17
namespace basegfx
18
{
19
    class SystemDependentData;
20
    typedef std::shared_ptr<SystemDependentData> SystemDependentData_SharedPtr;
21
    typedef std::weak_ptr<SystemDependentData> SystemDependentData_WeakPtr;
22
23
    class BASEGFX_DLLPUBLIC SystemDependentDataManager
24
    {
25
    private:
26
        // noncopyable
27
        SystemDependentDataManager(const SystemDependentDataManager&) = delete;
28
        SystemDependentDataManager& operator=(const SystemDependentDataManager&) = delete;
29
30
    public:
31
        SystemDependentDataManager();
32
        virtual ~SystemDependentDataManager();
33
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;
39
40
        // flush all buffered data (e.g. cleanup/shutdown)
41
        virtual void flushAll() = 0;
42
    };
43
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_CairoPath,
52
        SDDType_ModifiedBitmap,
53
        SDDType_GraphicsPath,
54
        SDDType_GdiPlusBitmap
55
    };
56
57
    class BASEGFX_DLLPUBLIC SystemDependentData
58
    {
59
    private:
60
        // noncopyable
61
        SystemDependentData(const SystemDependentData&) = delete;
62
        SystemDependentData& operator=(const SystemDependentData&) = delete;
63
64
        // reference to a SystemDependentDataManager, probably
65
        // a single, globally used one, but not necessarily
66
        SystemDependentDataManager&     mrSystemDependentDataManager;
67
68
        // Type identifier
69
        SDD_Type                        maSystemDependentDataType;
70
71
        // Buffered CalculatedCycles, result of estimations using
72
        // getHoldCyclesInSeconds and estimateUsageInBytes, executed
73
        // using getHoldCyclesInSeconds. StartValue is 0 to detect
74
        // not-yet-calculated state
75
        sal_uInt32                      mnCalculatedCycles;
76
77
    public:
78
        SystemDependentData(
79
            SystemDependentDataManager& rSystemDependentDataManager,
80
            SDD_Type aSystemDependentDataType);
81
        virtual ~SystemDependentData();
82
83
        // allow access to call startUsage/endUsage/touchUsage
84
        // using getSystemDependentDataManager()
85
0
        SystemDependentDataManager& getSystemDependentDataManager() { return mrSystemDependentDataManager; }
86
87
        // read access to SDD_Type
88
0
        SDD_Type getSystemDependentDataType() const { return maSystemDependentDataType; }
89
90
        // Calculate HoldCyclesInSeconds based on using
91
        // getHoldCyclesInSeconds and estimateUsageInBytes, the
92
        // result is created once on-demand and buffered in
93
        // mnCalculatedCycles
94
        sal_uInt32 calculateCombinedHoldCyclesInSeconds() const;
95
96
        // Allow read access to the calculated cycles in seconds, this
97
        // can be e.g. used to determine if this instance got added
98
0
        sal_uInt32 getCombinedHoldCyclesInSeconds() const { return mnCalculatedCycles; }
99
100
        // Size estimation of the entry in bytes - does not have to
101
        // be used, but should be. Default returns zero what
102
        // means there is no size estimation available. Override to
103
        // offer useful data if you want to have better caching.
104
        virtual sal_Int64 estimateUsageInBytes() const;
105
    };
106
107
    class BASEGFX_DLLPUBLIC SystemDependentDataHolder
108
    {
109
    private:
110
        // Possibility to hold System-Dependent B2DPolygon-Representations
111
        std::unordered_map< SDD_Type, SystemDependentData_WeakPtr > maSystemDependentReferences;
112
113
        // noncopyable
114
        SystemDependentDataHolder(const SystemDependentDataHolder&) = delete;
115
        SystemDependentDataHolder& operator=(const SystemDependentDataHolder&) = delete;
116
117
    public:
118
        SystemDependentDataHolder();
119
        virtual ~SystemDependentDataHolder();
120
121
        void addOrReplaceSystemDependentData(SystemDependentData_SharedPtr& rData);
122
        SystemDependentData_SharedPtr getSystemDependentData(SDD_Type aType) const;
123
    };
124
} // end of namespace basegfx
125
126
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */