Coverage Report

Created: 2025-07-07 10:01

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