summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-07-02 12:20:33 +0200
committerPaul Lemire <paul.lemire@kdab.com>2015-07-02 20:11:13 +0000
commitf6e989709cef935027ae5b822328004527ff3711 (patch)
tree1c3a645ff8ce5627071fb0724b9601d049da7ee5
parent01e371dfaff7697456cf91d32d017ee994ba50f9 (diff)
QFrameAllocator add a new isEmpty method
+ Unit tests Will help making sure everything is properly deleted after submitting the RenderViews. Change-Id: I097e02b095ad6ffd02db07a406a33982a794b7eb Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/core/resources/qframeallocator.cpp19
-rw-r--r--src/core/resources/qframeallocator.h1
-rw-r--r--src/core/resources/qframeallocator_p.h1
-rw-r--r--tests/auto/core/qframeallocator/tst_qframeallocator.cpp38
4 files changed, 59 insertions, 0 deletions
diff --git a/src/core/resources/qframeallocator.cpp b/src/core/resources/qframeallocator.cpp
index c62e7ad0d..3e83e29bf 100644
--- a/src/core/resources/qframeallocator.cpp
+++ b/src/core/resources/qframeallocator.cpp
@@ -104,6 +104,16 @@ int QFrameAllocator::allocatorPoolSize() const
return d->m_allocatorPool.size();
}
+bool QFrameAllocator::isEmpty() const
+{
+ Q_D(const QFrameAllocator);
+ Q_FOREACH (const QFixedFrameAllocator &allocator, d->m_allocatorPool) {
+ if (!allocator.isEmpty())
+ return false;
+ }
+ return true;
+}
+
uint QFrameAllocator::totalChunkCount() const
{
Q_D(const QFrameAllocator);
@@ -203,6 +213,15 @@ void QFixedFrameAllocator::clear()
m_chunks[i].clear(m_blockSize, m_nbrBlock);
}
+bool QFixedFrameAllocator::isEmpty() const
+{
+ Q_FOREACH (const QFrameChunk &chunck, m_chunks) {
+ if (chunck.m_blocksAvailable != chunck.m_maxBlocksAvailable)
+ return false;
+ }
+ return true;
+}
+
// QFrameChuck is agnostic about blocksize
// However if it was initialized with a block size of 16
// You should then pass 16 to allocate and deallocate
diff --git a/src/core/resources/qframeallocator.h b/src/core/resources/qframeallocator.h
index 91c8c1c5f..4fab92e91 100644
--- a/src/core/resources/qframeallocator.h
+++ b/src/core/resources/qframeallocator.h
@@ -84,6 +84,7 @@ public:
uint maxObjectSize() const;
uint totalChunkCount() const;
int allocatorPoolSize() const;
+ bool isEmpty() const;
private:
Q_DECLARE_PRIVATE(QFrameAllocator)
diff --git a/src/core/resources/qframeallocator_p.h b/src/core/resources/qframeallocator_p.h
index 990066138..471691e8e 100644
--- a/src/core/resources/qframeallocator_p.h
+++ b/src/core/resources/qframeallocator_p.h
@@ -75,6 +75,7 @@ public:
void trim();
void release();
void clear();
+ bool isEmpty() const;
inline int chunkCount() const { return m_chunks.size(); }
inline uchar pageSize() const { return m_nbrBlock; }
diff --git a/tests/auto/core/qframeallocator/tst_qframeallocator.cpp b/tests/auto/core/qframeallocator/tst_qframeallocator.cpp
index 821053fd8..38c97ed6d 100644
--- a/tests/auto/core/qframeallocator/tst_qframeallocator.cpp
+++ b/tests/auto/core/qframeallocator/tst_qframeallocator.cpp
@@ -102,6 +102,7 @@ private slots:
void allocateSubclass();
void deallocateSubclass();
void clearQFrameAllocator();
+ void isEmptyQFrameAllocator();
};
void tst_QFrameAllocator::initQFrameChunk()
@@ -676,6 +677,43 @@ void tst_QFrameAllocator::clearQFrameAllocator()
}
}
+void tst_QFrameAllocator::isEmptyQFrameAllocator()
+{
+ // GIVEN
+ Qt3D::QFrameAllocator f(128, 32);
+
+
+ // WHEN
+ for (int i = 0; i < 256; ++i)
+ f.allocate<composed>();
+ // THEN
+ QVERIFY(!f.isEmpty());
+
+ // WHEN
+ f.clear();
+ // THEN
+ QVERIFY(f.isEmpty());
+
+ for (int i = 0; i < 256; ++i) {
+
+ // GIVEN
+ QVector<composed *> composeds;
+ for (int j = 0; j < 256; ++j) {
+ composed *c = f.allocate<composed>();
+ c ->t = i * j;
+ composeds << c;
+ }
+ // THEN
+ QVERIFY(!f.isEmpty());
+
+ // WHEN
+ for (int j = 0; j < 256; ++j)
+ f.deallocate(composeds.takeAt(0));
+ // THEN
+ QVERIFY(f.isEmpty());
+ }
+}
+
QTEST_APPLESS_MAIN(tst_QFrameAllocator)
#include "tst_qframeallocator.moc"