Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/inc/graphic/Manager.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 <rtl/strbuf.hxx>
14
#include <vcl/dropcache.hxx>
15
#include <vcl/timer.hxx>
16
17
#include <memory>
18
#include <mutex>
19
#include <chrono>
20
#include <o3tl/sorted_vector.hxx>
21
22
namespace vcl::graphic
23
{
24
class MemoryManaged;
25
26
class VCL_DLLPUBLIC MemoryManager final : public CacheOwner
27
{
28
private:
29
    o3tl::sorted_vector<MemoryManaged*> maObjectList;
30
    sal_Int64 mnTotalSize = 0;
31
    std::mutex maMutex; // instead of SolarMutex because graphics can live past vcl main
32
33
    std::chrono::seconds mnAllowedIdleTime = std::chrono::seconds(1);
34
    bool mbSwapEnabled = true;
35
    bool mbReducingGraphicMemory = false;
36
    sal_Int64 mnMemoryLimit = 10'000'000;
37
    Timer maSwapOutTimer;
38
    sal_Int32 mnTimeout = 1'000;
39
    sal_Int64 mnSmallFrySize = 100'000;
40
41
    DECL_LINK(ReduceMemoryTimerHandler, Timer*, void);
42
43
public:
44
    MemoryManager();
45
    void registerObject(MemoryManaged* pObject);
46
    void unregisterObject(MemoryManaged* pObject);
47
    void changeExisting(MemoryManaged* pObject, sal_Int64 nNewSize);
48
49
    void swappedIn(MemoryManaged* pObject, sal_Int64 nNewSize);
50
    void swappedOut(MemoryManaged* pObject, sal_Int64 nNewSize);
51
52
    static MemoryManager& get();
53
0
    o3tl::sorted_vector<MemoryManaged*> const& getManagedObjects() { return maObjectList; }
54
0
    sal_Int64 getTotalSize() { return mnTotalSize; }
55
56
    void checkStartReduceTimer();
57
    void reduceMemory(std::unique_lock<std::mutex>& rGuard, bool bDropAll = false);
58
    void loopAndReduceMemory(std::unique_lock<std::mutex>& rGuard, bool bDropAll = false);
59
    virtual OUString getCacheName() const override;
60
    virtual bool dropCaches() override;
61
    virtual void dumpState(rtl::OStringBuffer& rState) override;
62
};
63
64
} // end namespace vcl::graphic
65
66
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */