ShmPool returns QWeakPointer<Buffer> instead of Buffer*
The Buffers are exclusively hold by ShmPool. The user of a Buffer is not supposed to delete it as a no longer used Buffer should be reused by the ShmPool. To make it obvious that the ownership of the pointer is not passed to the user the return type is changed to QWeakPointer. This also allows the ShmPool to destroy Buffers as needed.
This commit is contained in:
parent
aa26a42432
commit
6f2d49e680
2 changed files with 12 additions and 12 deletions
|
@ -157,7 +157,7 @@ void TestShmPool::testCreateBufferFromImage()
|
|||
QImage img(24, 24, QImage::Format_ARGB32);
|
||||
img.fill(Qt::black);
|
||||
QVERIFY(!img.isNull());
|
||||
auto buffer = m_shmPool->createBuffer(img);
|
||||
auto buffer = m_shmPool->createBuffer(img).toStrongRef();
|
||||
QVERIFY(buffer);
|
||||
QCOMPARE(buffer->size(), img.size());
|
||||
QImage img2(buffer->address(), img.width(), img.height(), QImage::Format_ARGB32);
|
||||
|
@ -170,7 +170,7 @@ void TestShmPool::testCreateBufferFromData()
|
|||
QImage img(24, 24, QImage::Format_ARGB32);
|
||||
img.fill(Qt::black);
|
||||
QVERIFY(!img.isNull());
|
||||
auto buffer = m_shmPool->createBuffer(img.size(), img.bytesPerLine(), img.constBits());
|
||||
auto buffer = m_shmPool->createBuffer(img.size(), img.bytesPerLine(), img.constBits()).toStrongRef();
|
||||
QVERIFY(buffer);
|
||||
QCOMPARE(buffer->size(), img.size());
|
||||
QImage img2(buffer->address(), img.width(), img.height(), QImage::Format_ARGB32);
|
||||
|
@ -183,13 +183,13 @@ void TestShmPool::testReuseBuffer()
|
|||
QImage img(24, 24, QImage::Format_ARGB32);
|
||||
img.fill(Qt::black);
|
||||
QVERIFY(!img.isNull());
|
||||
auto buffer = m_shmPool->createBuffer(img);
|
||||
auto buffer = m_shmPool->createBuffer(img).toStrongRef();
|
||||
QVERIFY(buffer);
|
||||
buffer->setReleased(true);
|
||||
buffer->setUsed(false);
|
||||
|
||||
// same image should get the same buffer
|
||||
auto buffer2 = m_shmPool->createBuffer(img);
|
||||
auto buffer2 = m_shmPool->createBuffer(img).toStrongRef();
|
||||
QCOMPARE(buffer, buffer2);
|
||||
buffer2->setReleased(true);
|
||||
buffer2->setUsed(false);
|
||||
|
@ -202,7 +202,7 @@ void TestShmPool::testReuseBuffer()
|
|||
QImage img2(24, 24, QImage::Format_RGB32);
|
||||
img2.fill(Qt::black);
|
||||
QVERIFY(!img2.isNull());
|
||||
auto buffer4 = m_shmPool->createBuffer(img2);
|
||||
auto buffer4 = m_shmPool->createBuffer(img2).toStrongRef();
|
||||
QVERIFY(buffer4);
|
||||
QVERIFY(buffer4 != buffer2);
|
||||
QVERIFY(buffer4 != buffer3);
|
||||
|
|
|
@ -265,9 +265,9 @@ void TestWaylandSurface::testAttachBuffer()
|
|||
QImage blue(24, 24, QImage::Format_ARGB32_Premultiplied);
|
||||
blue.fill(QColor(0, 0, 255, 128));
|
||||
|
||||
wl_buffer *blackBuffer = *(pool.createBuffer(black));
|
||||
KWayland::Client::Buffer *redBuffer = pool.createBuffer(red);
|
||||
KWayland::Client::Buffer *blueBuffer = pool.createBuffer(blue);
|
||||
wl_buffer *blackBuffer = *(pool.createBuffer(black).data());
|
||||
auto redBuffer = pool.createBuffer(red);
|
||||
auto blueBuffer = pool.createBuffer(blue).toStrongRef();
|
||||
|
||||
QCOMPARE(blueBuffer->format(), KWayland::Client::Buffer::Format::ARGB32);
|
||||
QCOMPARE(blueBuffer->size(), blue.size());
|
||||
|
@ -275,7 +275,7 @@ void TestWaylandSurface::testAttachBuffer()
|
|||
QVERIFY(!blueBuffer->isUsed());
|
||||
QCOMPARE(blueBuffer->stride(), blue.bytesPerLine());
|
||||
|
||||
s->attachBuffer(redBuffer);
|
||||
s->attachBuffer(redBuffer.data());
|
||||
s->attachBuffer(blackBuffer);
|
||||
s->damage(QRect(0, 0, 24, 24));
|
||||
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
||||
|
@ -303,12 +303,12 @@ void TestWaylandSurface::testAttachBuffer()
|
|||
QCOMPARE(buffer2->data().format(), QImage::Format_ARGB32);
|
||||
buffer2->unref();
|
||||
QVERIFY(buffer2->isReferenced());
|
||||
QVERIFY(!redBuffer->isReleased());
|
||||
QVERIFY(!redBuffer.data()->isReleased());
|
||||
|
||||
// render another frame
|
||||
blueBuffer->setUsed(true);
|
||||
QVERIFY(blueBuffer->isUsed());
|
||||
s->attachBuffer(blueBuffer);
|
||||
s->attachBuffer(blueBuffer.data());
|
||||
s->damage(QRect(0, 0, 24, 24));
|
||||
QSignalSpy frameRenderedSpy(s, SIGNAL(frameRendered()));
|
||||
QVERIFY(frameRenderedSpy.isValid());
|
||||
|
@ -319,7 +319,7 @@ void TestWaylandSurface::testAttachBuffer()
|
|||
delete buffer2;
|
||||
// TODO: we should have a signal on when the Buffer gets released
|
||||
QTest::qWait(100);
|
||||
QVERIFY(redBuffer->isReleased());
|
||||
QVERIFY(redBuffer.data()->isReleased());
|
||||
|
||||
KWayland::Server::BufferInterface *buffer3 = serverSurface->buffer();
|
||||
buffer3->ref();
|
||||
|
|
Loading…
Reference in a new issue