Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/inc/impgraph.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
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#pragma once
21
22
#include <vcl/dllapi.h>
23
#include <vcl/GraphicExternalLink.hxx>
24
#include <vcl/gdimtf.hxx>
25
#include <vcl/graph.hxx>
26
#include "graphic/Manager.hxx"
27
#include "graphic/MemoryManaged.hxx"
28
#include "graphic/GraphicID.hxx"
29
#include "graphic/BitmapContainer.hxx"
30
#include "graphic/AnimationContainer.hxx"
31
#include "graphic/SwapInfo.hxx"
32
#include <optional>
33
34
class OutputDevice;
35
class GfxLink;
36
class ImpSwapFile;
37
38
enum class GraphicContentType : sal_Int32
39
{
40
    Bitmap,
41
    Animation,
42
    Vector
43
};
44
45
class SAL_DLLPUBLIC_RTTI ImpGraphic final : public vcl::graphic::MemoryManaged
46
{
47
    friend class Graphic;
48
    friend class GraphicID;
49
50
private:
51
    Bitmap maCachedBitmap;
52
    GDIMetaFile maMetaFile;
53
    std::shared_ptr<BitmapContainer> mpBitmapContainer;
54
55
    /// If maBitmapEx is empty, this preferred size will be set on it when it gets initialized.
56
    Size                         maExPrefSize;
57
    SwapInfo maSwapInfo;
58
    std::shared_ptr<AnimationContainer> mpAnimationContainer;
59
    std::shared_ptr<ImpSwapFile> mpSwapFile;
60
    std::shared_ptr<GfxLink>     mpGfxLink;
61
    std::shared_ptr<VectorGraphicData> maVectorGraphicData;
62
63
    GraphicType                  meType = GraphicType::NONE;
64
    mutable sal_Int64 mnSizeBytes = 0;
65
    bool                         mbSwapOut = false;
66
    bool                         mbDummyContext = false;
67
    // cache checksum computation
68
    mutable BitmapChecksum       mnChecksum = 0;
69
70
    std::optional<GraphicID>     mxGraphicID;
71
    GraphicExternalLink          maGraphicExternalLink;
72
73
    // atomic because it is touched in parallel from the drawinglayer parallel rendering stuff in ScenePrimitive2D::create2DDecomposition
74
    mutable std::atomic<std::chrono::high_resolution_clock::time_point> maLastUsed = std::chrono::high_resolution_clock::now();
75
    bool mbPrepared = false;
76
77
public:
78
    ImpGraphic(bool bDefault = false);
79
    ImpGraphic( const ImpGraphic& rImpGraphic );
80
    ImpGraphic( ImpGraphic&& rImpGraphic ) noexcept;
81
    ImpGraphic( GraphicExternalLink aExternalLink);
82
    ImpGraphic(std::shared_ptr<GfxLink> xGfxLink, sal_Int32 nPageIndex = 0);
83
    ImpGraphic( const Bitmap& rBmp );
84
    ImpGraphic(const std::shared_ptr<VectorGraphicData>& rVectorGraphicDataPtr);
85
    ImpGraphic( const Animation& rAnimation );
86
    ImpGraphic( const GDIMetaFile& rMtf );
87
    ~ImpGraphic();
88
89
    void setPrepared(bool bAnimated, const Size* pSizeHint);
90
91
private:
92
93
    ImpGraphic&         operator=( const ImpGraphic& rImpGraphic );
94
    ImpGraphic&         operator=( ImpGraphic&& rImpGraphic );
95
    bool                operator==( const ImpGraphic& rImpGraphic ) const;
96
0
    bool                operator!=( const ImpGraphic& rImpGraphic ) const { return !( *this == rImpGraphic ); }
97
98
    OUString const & getOriginURL() const
99
107k
    {
100
107k
        return maGraphicExternalLink.msURL;
101
107k
    }
102
103
    void setOriginURL(OUString const & rOriginURL)
104
48.0k
    {
105
48.0k
        maGraphicExternalLink.msURL = rOriginURL;
106
48.0k
    }
107
108
    OString getUniqueID()
109
0
    {
110
0
        if (!mxGraphicID)
111
0
            mxGraphicID.emplace(*this);
112
0
        return mxGraphicID->getIDString();
113
0
    }
114
115
    void createSwapInfo();
116
    void restoreFromSwapInfo();
117
118
    void                clearGraphics();
119
    void                clear();
120
121
407k
    GraphicType         getType() const { return meType;}
122
    bool                isSupportedGraphic() const;
123
124
    bool                isTransparent() const;
125
    bool                isAlpha() const;
126
    bool                isAnimated() const;
127
    bool                isEPS() const;
128
129
    bool isAvailable() const;
130
    bool makeAvailable();
131
132
    /// Gives direct access to the contained Bitmap.
133
    const Bitmap&       getBitmapRef() const;
134
    Animation           getAnimation() const;
135
    const GDIMetaFile&  getGDIMetaFile() const;
136
137
    Size                getSizePixel() const;
138
139
    Size                getPrefSize() const;
140
    void                setPrefSize( const Size& rPrefSize );
141
142
    MapMode             getPrefMapMode() const;
143
    void                setPrefMapMode( const MapMode& rPrefMapMode );
144
145
    sal_Int64 getSizeBytes() const;
146
147
    void ensureCurrentSizeInBytes();
148
149
    void                draw(OutputDevice& rOutDev, const Point& rDestPt,
150
                             const Size& rDestSize) const;
151
152
    void                startAnimation(OutputDevice& rOutDev,
153
                                       const Point& rDestPt,
154
                                       const Size& rDestSize,
155
                                       tools::Long nRendererId,
156
                                       OutputDevice* pFirstFrameOutDev);
157
    void                stopAnimation( const OutputDevice* pOutputDevice,
158
                                           tools::Long nRendererId );
159
160
    void                setAnimationNotifyHdl( const Link<Animation*,void>& rLink );
161
    Link<Animation*,void> getAnimationNotifyHdl() const;
162
163
    sal_uInt32          getAnimationLoopCount() const;
164
165
private:
166
    // swapping methods
167
    bool swapInFromStream(SvStream& rStream);
168
    bool swapInGraphic(SvStream& rStream);
169
170
    bool swapInContent(SvStream& rStream);
171
    bool swapOutContent(SvStream& rStream);
172
    bool swapOutGraphic(SvStream& rStream);
173
    // end swapping
174
175
    Bitmap getBitmap(const GraphicConversionParameters& rParameters) const;
176
177
0
    void                setDummyContext( bool value ) { mbDummyContext = value; }
178
20.8k
    bool                isDummyContext() const { return mbDummyContext; }
179
    void                setGfxLink( const std::shared_ptr<GfxLink>& );
180
    const std::shared_ptr<GfxLink> & getSharedGfxLink() const;
181
    GfxLink             getGfxLink() const;
182
    bool                isGfxLink() const;
183
184
    BitmapChecksum      getChecksum() const;
185
186
    const std::shared_ptr<VectorGraphicData>& getVectorGraphicData() const;
187
188
    /// Gets the bitmap replacement for a vector graphic.
189
    // Hide volatile state of maBitmapEx when using maVectorGraphicData into this method
190
    void updateBitmapFromVectorGraphic(const Size& pixelSize = {}) const;
191
192
    bool ensureAvailable () const;
193
194
    sal_Int32 getPageNumber() const;
195
196
    // Set the pref size, but don't force swap-in
197
    void setValuesForPrefSize(const Size& rPrefSize);
198
    // Set the pref map mode, but don't force swap-in
199
    void setValuesForPrefMapMod(const MapMode& rPrefMapMode);
200
201
    bool canReduceMemory() const override;
202
    bool reduceMemory() override;
203
    std::chrono::high_resolution_clock::time_point getLastUsed() const override;
204
    void resetLastUsed() const;
205
206
public:
207
0
    void resetChecksum() { mnChecksum = 0; }
208
    bool swapIn();
209
    VCL_DLLPUBLIC bool swapOut();
210
891k
    bool isSwappedOut() const { return mbSwapOut; }
211
    VCL_DLLPUBLIC SvStream* getSwapFileStream() const;
212
    // public only because of use in GraphicFilter
213
    void updateFromLoadedGraphic(const ImpGraphic* graphic);
214
    void dumpState(rtl::OStringBuffer &rState) override;
215
};
216
217
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */