Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSwappedDataStore Class Reference

#include <kis_swapped_data_store.h>

Public Member Functions

void debugStatistics ()
 
void forgetTileData (KisTileData *td)
 
 KisSwappedDataStore ()
 
quint64 numTiles () const
 
void swapInTileData (KisTileData *td)
 
qint64 totalSwapMemoryUsed () const
 
bool trySwapOutTileData (KisTileData *td)
 
 ~KisSwappedDataStore ()
 

Private Attributes

KisChunkAllocatorm_allocator
 
QByteArray m_buffer
 
KisAbstractTileCompressorm_compressor
 
QMutex m_lock
 
KisMemoryWindowm_swapSpace
 
qint64 m_totalSwapMemoryUsed
 

Detailed Description

Definition at line 22 of file kis_swapped_data_store.h.

Constructor & Destructor Documentation

◆ KisSwappedDataStore()

KisSwappedDataStore::KisSwappedDataStore ( )

Definition at line 17 of file kis_swapped_data_store.cpp.

19{
20 KisImageConfig config(true);
21 const quint64 maxSwapSize = config.maxSwapSize() * MiB;
22 const quint64 swapSlabSize = config.swapSlabSize() * MiB;
23 const quint64 swapWindowSize = config.swapWindowSize() * MiB;
24
25 m_allocator = new KisChunkAllocator(swapSlabSize, maxSwapSize);
26 m_swapSpace = new KisMemoryWindow(config.swapDir(), swapWindowSize);
27
28 // FIXME: use a factory after the patch is committed
30}
KisMemoryWindow * m_swapSpace
KisAbstractTileCompressor * m_compressor
KisChunkAllocator * m_allocator
#define MiB

References m_allocator, m_compressor, m_swapSpace, KisImageConfig::maxSwapSize(), MiB, KisImageConfig::swapDir(), KisImageConfig::swapSlabSize(), and KisImageConfig::swapWindowSize().

◆ ~KisSwappedDataStore()

KisSwappedDataStore::~KisSwappedDataStore ( )

Definition at line 32 of file kis_swapped_data_store.cpp.

33{
34 delete m_compressor;
35 delete m_swapSpace;
36 delete m_allocator;
37}

References m_allocator, m_compressor, and m_swapSpace.

Member Function Documentation

◆ debugStatistics()

void KisSwappedDataStore::debugStatistics ( )

Some debugging output

Definition at line 115 of file kis_swapped_data_store.cpp.

116{
119}
qreal debugFragmentation(bool toStderr=true)
bool sanityCheck(bool pleaseCrash=true)

References KisChunkAllocator::debugFragmentation(), m_allocator, and KisChunkAllocator::sanityCheck().

◆ forgetTileData()

void KisSwappedDataStore::forgetTileData ( KisTileData * td)

Forget all the information linked with the tile data. This should be done before deleting of the tile data, whose actual data is swapped-out

Definition at line 100 of file kis_swapped_data_store.cpp.

101{
102 QMutexLocker locker(&m_lock);
103
105
107 td->setSwapChunk(KisChunk());
108}
void freeChunk(KisChunk chunk)
quint64 size() const
KisChunk swapChunk() const
void setSwapChunk(KisChunk chunk)

References KisChunkAllocator::freeChunk(), m_allocator, m_lock, m_totalSwapMemoryUsed, KisTileData::setSwapChunk(), KisChunk::size(), and KisTileData::swapChunk().

◆ numTiles()

quint64 KisSwappedDataStore::numTiles ( ) const

Returns number of swapped out tile data objects

Definition at line 39 of file kis_swapped_data_store.cpp.

40{
41 // We are not acquiring the lock here...
42 // Hope QLinkedList will ensure atomic access to it's size...
43
44 return m_allocator->numChunks();
45}
quint64 numChunks() const

References m_allocator, and KisChunkAllocator::numChunks().

◆ swapInTileData()

void KisSwappedDataStore::swapInTileData ( KisTileData * td)

Restore the data of a td basing on information stored in the swap file. LOCKING: the lock on the tile data should be taken by the caller before making a call.

Definition at line 81 of file kis_swapped_data_store.cpp.

82{
83 Q_ASSERT(!td->data());
84 QMutexLocker locker(&m_lock);
85
86 // see comment in swapOutTileData()
87
88 KisChunk chunk = td->swapChunk();
89 m_totalSwapMemoryUsed -= chunk.size();
90
91 td->allocateMemory();
93
94 quint8 *ptr = m_swapSpace->getReadChunkPtr(chunk);
95 Q_ASSERT(ptr);
96 m_compressor->decompressTileData(ptr, chunk.size(), td);
97 m_allocator->freeChunk(chunk);
98}
virtual bool decompressTileData(quint8 *buffer, qint32 bufferSize, KisTileData *tileData)=0
quint8 * getReadChunkPtr(KisChunk readChunk)
quint8 * data() const
void allocateMemory()

References KisTileData::allocateMemory(), KisTileData::data(), KisAbstractTileCompressor::decompressTileData(), KisChunkAllocator::freeChunk(), KisMemoryWindow::getReadChunkPtr(), m_allocator, m_compressor, m_lock, m_swapSpace, m_totalSwapMemoryUsed, KisTileData::setSwapChunk(), KisChunk::size(), and KisTileData::swapChunk().

◆ totalSwapMemoryUsed()

qint64 KisSwappedDataStore::totalSwapMemoryUsed ( ) const

Returns the metric of the total memory stored in the swap in uncompressed form!

Definition at line 110 of file kis_swapped_data_store.cpp.

111{
113}

References m_totalSwapMemoryUsed.

◆ trySwapOutTileData()

bool KisSwappedDataStore::trySwapOutTileData ( KisTileData * td)

Swap out the data stored in the td to the swap file and free memory occupied by td->data(). LOCKING: the lock on the tile data should be taken by the caller before making a call.

We are expecting that the lock of KisTileData has already been taken by the caller for us. So we can modify the tile data freely.

Definition at line 47 of file kis_swapped_data_store.cpp.

48{
49 Q_ASSERT(td->data());
50 QMutexLocker locker(&m_lock);
51
58 const qint32 expectedBufferSize = m_compressor->tileDataBufferSize(td);
59 if(m_buffer.size() < expectedBufferSize)
60 m_buffer.resize(expectedBufferSize);
61
62 qint32 bytesWritten;
63 m_compressor->compressTileData(td, (quint8*) m_buffer.data(), m_buffer.size(), bytesWritten);
64
65 KisChunk chunk = m_allocator->getChunk(bytesWritten);
66 quint8 *ptr = m_swapSpace->getWriteChunkPtr(chunk);
67 if (!ptr) {
68 qWarning() << "swap out of tile failed";
69 return false;
70 }
71 memcpy(ptr, m_buffer.data(), bytesWritten);
72
73 td->releaseMemory();
74 td->setSwapChunk(chunk);
75
76 m_totalSwapMemoryUsed += chunk.size();
77
78 return true;
79}
virtual void compressTileData(KisTileData *tileData, quint8 *buffer, qint32 bufferSize, qint32 &bytesWritten)=0
virtual qint32 tileDataBufferSize(KisTileData *tileData)=0
KisChunk getChunk(quint64 size)
quint8 * getWriteChunkPtr(KisChunk writeChunk)
void releaseMemory()

References KisAbstractTileCompressor::compressTileData(), KisTileData::data(), KisChunkAllocator::getChunk(), KisMemoryWindow::getWriteChunkPtr(), m_allocator, m_buffer, m_compressor, m_lock, m_swapSpace, m_totalSwapMemoryUsed, KisTileData::releaseMemory(), KisTileData::setSwapChunk(), KisChunk::size(), and KisAbstractTileCompressor::tileDataBufferSize().

Member Data Documentation

◆ m_allocator

KisChunkAllocator* KisSwappedDataStore::m_allocator
private

Definition at line 71 of file kis_swapped_data_store.h.

◆ m_buffer

QByteArray KisSwappedDataStore::m_buffer
private

Definition at line 68 of file kis_swapped_data_store.h.

◆ m_compressor

KisAbstractTileCompressor* KisSwappedDataStore::m_compressor
private

Definition at line 69 of file kis_swapped_data_store.h.

◆ m_lock

QMutex KisSwappedDataStore::m_lock
private

Definition at line 74 of file kis_swapped_data_store.h.

◆ m_swapSpace

KisMemoryWindow* KisSwappedDataStore::m_swapSpace
private

Definition at line 72 of file kis_swapped_data_store.h.

◆ m_totalSwapMemoryUsed

qint64 KisSwappedDataStore::m_totalSwapMemoryUsed
private

Definition at line 76 of file kis_swapped_data_store.h.


The documentation for this class was generated from the following files: