1 /* 2 * Copyright (c) 2010 Dmitry Kazakov <dimula73@gmail.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 19 #ifndef __KIS_SWAPPED_DATA_STORE_H 20 #define __KIS_SWAPPED_DATA_STORE_H 21 22 #include "kritaimage_export.h" 23 24 #include <QMutex> 25 #include <QByteArray> 26 27 28 class QMutex; 29 class KisTileData; 30 class KisAbstractTileCompressor; 31 class KisChunkAllocator; 32 class KisMemoryWindow; 33 34 class KRITAIMAGE_EXPORT KisSwappedDataStore 35 { 36 public: 37 KisSwappedDataStore(); 38 ~KisSwappedDataStore(); 39 40 /** 41 * Returns number of swapped out tile data objects 42 */ 43 quint64 numTiles() const; 44 45 /** 46 * Swap out the data stored in the \a td to the swap file 47 * and free memory occupied by td->data(). 48 * LOCKING: the lock on the tile data should be taken 49 * by the caller before making a call. 50 */ 51 bool trySwapOutTileData(KisTileData *td); 52 53 /** 54 * Restore the data of a \a td basing on information 55 * stored in the swap file. 56 * LOCKING: the lock on the tile data should be taken 57 * by the caller before making a call. 58 */ 59 void swapInTileData(KisTileData *td); 60 61 /** 62 * Forget all the information linked with the tile data. 63 * This should be done before deleting of the tile data, 64 * whose actual data is swapped-out 65 */ 66 void forgetTileData(KisTileData *td); 67 68 /** 69 * Retorns the metric of the total memory stored in the swap 70 * in *uncompressed* form! 71 */ 72 qint64 totalMemoryMetric() const; 73 74 /** 75 * Some debugging output 76 */ 77 void debugStatistics(); 78 79 private: 80 QByteArray m_buffer; 81 KisAbstractTileCompressor *m_compressor; 82 83 KisChunkAllocator *m_allocator; 84 KisMemoryWindow *m_swapSpace; 85 86 QMutex m_lock; 87 88 qint64 m_memoryMetric; 89 }; 90 91 #endif /* __KIS_SWAPPED_DATA_STORE_H */ 92 93