File indexing completed on 2024-06-23 04:22:01

0001 /*
0002  *  SPDX-FileCopyrightText: 2010 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef __KIS_SWAPPED_DATA_STORE_H
0008 #define __KIS_SWAPPED_DATA_STORE_H
0009 
0010 #include "kritaimage_export.h"
0011 
0012 #include <QMutex>
0013 #include <QByteArray>
0014 
0015 
0016 class QMutex;
0017 class KisTileData;
0018 class KisAbstractTileCompressor;
0019 class KisChunkAllocator;
0020 class KisMemoryWindow;
0021 
0022 class KRITAIMAGE_EXPORT KisSwappedDataStore
0023 {
0024 public:
0025     KisSwappedDataStore();
0026     ~KisSwappedDataStore();
0027 
0028     /**
0029      * Returns number of swapped out tile data objects
0030      */
0031     quint64 numTiles() const;
0032 
0033     /**
0034      * Swap out the data stored in the \a td to the swap file
0035      * and free memory occupied by td->data().
0036      * LOCKING: the lock on the tile data should be taken
0037      *          by the caller before making a call.
0038      */
0039     bool trySwapOutTileData(KisTileData *td);
0040 
0041     /**
0042      * Restore the data of a \a td basing on information
0043      * stored in the swap file.
0044      * LOCKING: the lock on the tile data should be taken
0045      *          by the caller before making a call.
0046      */
0047     void swapInTileData(KisTileData *td);
0048 
0049     /**
0050      * Forget all the information linked with the tile data.
0051      * This should be done before deleting of the tile data,
0052      * whose actual data is swapped-out
0053      */
0054     void forgetTileData(KisTileData *td);
0055 
0056     /**
0057      * Returns the metric of the total memory stored in the swap
0058      * in *uncompressed* form!
0059      */
0060     qint64 totalSwapMemoryUsed() const;
0061 
0062     /**
0063      * Some debugging output
0064      */
0065     void debugStatistics();
0066 
0067 private:
0068     QByteArray m_buffer;
0069     KisAbstractTileCompressor *m_compressor;
0070 
0071     KisChunkAllocator *m_allocator;
0072     KisMemoryWindow *m_swapSpace;
0073 
0074     QMutex m_lock;
0075 
0076     qint64 m_totalSwapMemoryUsed;
0077 };
0078 
0079 #endif /* __KIS_SWAPPED_DATA_STORE_H */
0080