rhi: Remove runCleanup function
The rest of the framework uses cleanup callbacks in a way that implies that manually triggering the callbacks will lead to problems: components such as QQuickWidget register cleanup callbacks to get notified about the destruction of the QRhi. These callbacks should not be invoked at arbitrary times. There is no usage of this function anywhere in Qt. Remove it. Slightly extend the autotest by exercising the keyed registration functions as well. Change-Id: I88f1a1e9bc5a642b8e8b6238fe198f123bd55978 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
This commit is contained in:
parent
10f94fe497
commit
3f55ac90fc
@ -8808,7 +8808,7 @@ QRhi::~QRhi()
|
|||||||
if (!d)
|
if (!d)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
runCleanup();
|
d->runCleanup();
|
||||||
|
|
||||||
qDeleteAll(d->pendingDeleteResources);
|
qDeleteAll(d->pendingDeleteResources);
|
||||||
d->pendingDeleteResources.clear();
|
d->pendingDeleteResources.clear();
|
||||||
@ -9337,8 +9337,7 @@ QThread *QRhi::thread() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Registers a \a callback that is invoked either when the QRhi is destroyed,
|
Registers a \a callback that is invoked when the QRhi is destroyed.
|
||||||
or when runCleanup() is called.
|
|
||||||
|
|
||||||
The callback will run with the graphics resource still available, so this
|
The callback will run with the graphics resource still available, so this
|
||||||
provides an opportunity for the application to cleanly release QRhiResource
|
provides an opportunity for the application to cleanly release QRhiResource
|
||||||
@ -9346,7 +9345,7 @@ QThread *QRhi::thread() const
|
|||||||
the lifetime of resources stored in \c cache type of objects, where the
|
the lifetime of resources stored in \c cache type of objects, where the
|
||||||
cache holds QRhiResources or objects containing QRhiResources.
|
cache holds QRhiResources or objects containing QRhiResources.
|
||||||
|
|
||||||
\sa runCleanup(), ~QRhi()
|
\sa ~QRhi()
|
||||||
*/
|
*/
|
||||||
void QRhi::addCleanupCallback(const CleanupCallback &callback)
|
void QRhi::addCleanupCallback(const CleanupCallback &callback)
|
||||||
{
|
{
|
||||||
@ -9356,10 +9355,9 @@ void QRhi::addCleanupCallback(const CleanupCallback &callback)
|
|||||||
/*!
|
/*!
|
||||||
\overload
|
\overload
|
||||||
|
|
||||||
Registers \a callback to be invoked either when the QRhi is destroyed or
|
Registers \a callback to be invoked when the QRhi is destroyed. This
|
||||||
when runCleanup() is called. This overload takes an opaque pointer, \a key,
|
overload takes an opaque pointer, \a key, that is used to ensure that a
|
||||||
that is used to ensure that a given callback is registered (and so called)
|
given callback is registered (and so called) only once.
|
||||||
only once.
|
|
||||||
|
|
||||||
\sa removeCleanupCallback()
|
\sa removeCleanupCallback()
|
||||||
*/
|
*/
|
||||||
@ -9380,25 +9378,17 @@ void QRhi::removeCleanupCallback(const void *key)
|
|||||||
d->removeCleanupCallback(key);
|
d->removeCleanupCallback(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
void QRhiImplementation::runCleanup()
|
||||||
Invokes all registered cleanup functions. The list of cleanup callbacks it
|
|
||||||
then cleared. Normally destroying the QRhi does this automatically, but
|
|
||||||
sometimes it can be useful to trigger cleanup in order to release all
|
|
||||||
cached, non-essential resources.
|
|
||||||
|
|
||||||
\sa addCleanupCallback()
|
|
||||||
*/
|
|
||||||
void QRhi::runCleanup()
|
|
||||||
{
|
{
|
||||||
for (const CleanupCallback &f : std::as_const(d->cleanupCallbacks))
|
for (const QRhi::CleanupCallback &f : std::as_const(cleanupCallbacks))
|
||||||
f(this);
|
f(q);
|
||||||
|
|
||||||
d->cleanupCallbacks.clear();
|
cleanupCallbacks.clear();
|
||||||
|
|
||||||
for (auto it = d->keyedCleanupCallbacks.cbegin(), end = d->keyedCleanupCallbacks.cend(); it != end; ++it)
|
for (auto it = keyedCleanupCallbacks.cbegin(), end = keyedCleanupCallbacks.cend(); it != end; ++it)
|
||||||
it.value()(this);
|
it.value()(q);
|
||||||
|
|
||||||
d->keyedCleanupCallbacks.clear();
|
keyedCleanupCallbacks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -1984,7 +1984,6 @@ public:
|
|||||||
void addCleanupCallback(const CleanupCallback &callback);
|
void addCleanupCallback(const CleanupCallback &callback);
|
||||||
void addCleanupCallback(const void *key, const CleanupCallback &callback);
|
void addCleanupCallback(const void *key, const CleanupCallback &callback);
|
||||||
void removeCleanupCallback(const void *key);
|
void removeCleanupCallback(const void *key);
|
||||||
void runCleanup();
|
|
||||||
|
|
||||||
QRhiGraphicsPipeline *newGraphicsPipeline();
|
QRhiGraphicsPipeline *newGraphicsPipeline();
|
||||||
QRhiComputePipeline *newComputePipeline();
|
QRhiComputePipeline *newComputePipeline();
|
||||||
|
@ -242,6 +242,8 @@ public:
|
|||||||
|
|
||||||
int effectiveSampleCount(int sampleCount) const;
|
int effectiveSampleCount(int sampleCount) const;
|
||||||
|
|
||||||
|
void runCleanup();
|
||||||
|
|
||||||
QRhi *q;
|
QRhi *q;
|
||||||
|
|
||||||
static const int MAX_SHADER_CACHE_ENTRIES = 128;
|
static const int MAX_SHADER_CACHE_ENTRIES = 128;
|
||||||
|
@ -371,10 +371,10 @@ void tst_QRhi::create()
|
|||||||
cleanupOk += 1;
|
cleanupOk += 1;
|
||||||
};
|
};
|
||||||
rhi->addCleanupCallback(cleanupFunc);
|
rhi->addCleanupCallback(cleanupFunc);
|
||||||
rhi->runCleanup();
|
|
||||||
QCOMPARE(cleanupOk, 1);
|
|
||||||
cleanupOk = 0;
|
|
||||||
rhi->addCleanupCallback(cleanupFunc);
|
rhi->addCleanupCallback(cleanupFunc);
|
||||||
|
rhi->addCleanupCallback(reinterpret_cast<const void *>(quintptr(1234)), cleanupFunc);
|
||||||
|
rhi->addCleanupCallback(reinterpret_cast<const void *>(quintptr(12345)), cleanupFunc);
|
||||||
|
rhi->removeCleanupCallback(reinterpret_cast<const void *>(quintptr(1234)));
|
||||||
|
|
||||||
QRhiResourceUpdateBatch *resUpd = rhi->nextResourceUpdateBatch();
|
QRhiResourceUpdateBatch *resUpd = rhi->nextResourceUpdateBatch();
|
||||||
QVERIFY(resUpd);
|
QVERIFY(resUpd);
|
||||||
@ -512,7 +512,7 @@ void tst_QRhi::create()
|
|||||||
QVERIFY(!rhi->isDeviceLost());
|
QVERIFY(!rhi->isDeviceLost());
|
||||||
|
|
||||||
rhi.reset();
|
rhi.reset();
|
||||||
QCOMPARE(cleanupOk, 1);
|
QCOMPARE(cleanupOk, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user