Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx
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
#include <sal/config.h>
21
22
#include <comphelper/configuration.hxx>
23
#include <drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx>
24
#include <drawinglayer/primitive2d/BufferedDecompositionFlusher.hxx>
25
26
namespace drawinglayer::primitive2d
27
{
28
bool BufferedDecompositionPrimitive2D::hasBuffered2DDecomposition() const
29
7.95k
{
30
7.95k
    if (!mbFlushOnTimer)
31
7.95k
        return maBuffered2DDecomposition.is();
32
0
    else
33
0
    {
34
0
        std::lock_guard Guard(maCallbackLock);
35
0
        return maBuffered2DDecomposition.is();
36
0
    }
37
7.95k
}
38
39
void BufferedDecompositionPrimitive2D::setBuffered2DDecomposition(Primitive2DReference rNew)
40
0
{
41
0
    if (!mbFlushOnTimer)
42
0
    {
43
        // no flush used, just set
44
0
        maBuffered2DDecomposition = std::move(rNew);
45
0
    }
46
0
    else
47
0
    {
48
        // decomposition changed, touch
49
0
        maLastAccess = std::chrono::steady_clock::now();
50
0
        BufferedDecompositionFlusher::update(this);
51
52
        // tdf#158913 need to secure change when flush/multithreading is in use
53
0
        std::lock_guard Guard(maCallbackLock);
54
0
        maBuffered2DDecomposition = std::move(rNew);
55
0
    }
56
0
}
57
58
BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D()
59
390k
    : maBuffered2DDecomposition()
60
390k
    , maCallbackLock()
61
390k
    , mbFlushOnTimer(false)
62
390k
{
63
390k
}
64
65
BufferedDecompositionPrimitive2D::~BufferedDecompositionPrimitive2D()
66
390k
{
67
390k
    if (mbFlushOnTimer)
68
0
        BufferedDecompositionFlusher::remove(this);
69
390k
}
70
71
void BufferedDecompositionPrimitive2D::get2DDecomposition(
72
    Primitive2DDecompositionVisitor& rVisitor,
73
    const geometry::ViewInformation2D& rViewInformation) const
74
373k
{
75
373k
    if (!mbFlushOnTimer)
76
373k
    {
77
        // no flush/multithreading is in use, just call
78
373k
        if (!maBuffered2DDecomposition)
79
369k
            maBuffered2DDecomposition = create2DDecomposition(rViewInformation);
80
373k
        rVisitor.visit(maBuffered2DDecomposition);
81
373k
    }
82
0
    else
83
0
    {
84
        // tdf#158913 need to secure 'visit' when flush/multithreading is in use,
85
        // so that the local non-ref-Counted instance of the decomposition gets not
86
        // manipulated (e.g. deleted)
87
0
        Primitive2DReference xTmp;
88
0
        {
89
0
            maLastAccess = std::chrono::steady_clock::now();
90
            // only hold the lock for long enough to get a valid reference
91
0
            std::lock_guard Guard(maCallbackLock);
92
0
            if (!maBuffered2DDecomposition)
93
0
            {
94
0
                maBuffered2DDecomposition = create2DDecomposition(rViewInformation);
95
0
                BufferedDecompositionFlusher::update(this);
96
0
            }
97
0
            xTmp = maBuffered2DDecomposition;
98
0
        }
99
0
        rVisitor.visit(xTmp);
100
0
    }
101
373k
}
102
103
void BufferedDecompositionPrimitive2D::activateFlushOnTimer()
104
7.78k
{
105
7.78k
    if (comphelper::IsFuzzing())
106
7.78k
        return;
107
0
    mbFlushOnTimer = true;
108
0
}
109
110
} // end of namespace drawinglayer::primitive2d
111
112
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */