mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-24 01:34:08 +02:00
Report ScriptableResource memory cost to engine
This commit is contained in:
parent
5ec82fa43d
commit
1a0a623d5f
4 changed files with 37 additions and 11 deletions
|
@ -128,6 +128,13 @@ void ScriptableResource::release() {
|
||||||
_resource.reset();
|
_resource.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptableResource::updateMemoryCost(const QObject* engine) {
|
||||||
|
if (_resource && !_resource->isInScript()) {
|
||||||
|
_resource->setInScript(true);
|
||||||
|
connect(_resource.data(), SIGNAL(updateSize(qint64)), engine, SLOT(updateMemoryCost(qint64)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptableResource::finished(bool success) {
|
void ScriptableResource::finished(bool success) {
|
||||||
disconnectHelper();
|
disconnectHelper();
|
||||||
|
|
||||||
|
@ -329,6 +336,7 @@ QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl&
|
||||||
getResource(fallback, QUrl(), true) : QSharedPointer<Resource>(), delayLoad, extra);
|
getResource(fallback, QUrl(), true) : QSharedPointer<Resource>(), delayLoad, extra);
|
||||||
resource->setSelf(resource);
|
resource->setSelf(resource);
|
||||||
resource->setCache(this);
|
resource->setCache(this);
|
||||||
|
connect(resource.data(), &Resource::updateSize, this, &ResourceCache::updateTotalSize);
|
||||||
{
|
{
|
||||||
QWriteLocker locker(&_resourcesLock);
|
QWriteLocker locker(&_resourcesLock);
|
||||||
_resources.insert(url, resource);
|
_resources.insert(url, resource);
|
||||||
|
@ -414,8 +422,8 @@ void ResourceCache::removeResource(const QUrl& url, qint64 size) {
|
||||||
_totalResourcesSize -= size;
|
_totalResourcesSize -= size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceCache::updateTotalSize(const qint64& oldSize, const qint64& newSize) {
|
void ResourceCache::updateTotalSize(const qint64& deltaSize) {
|
||||||
_totalResourcesSize += (newSize - oldSize);
|
_totalResourcesSize += deltaSize;
|
||||||
emit dirty();
|
emit dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,7 +600,7 @@ void Resource::finishedLoading(bool success) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::setSize(const qint64& bytes) {
|
void Resource::setSize(const qint64& bytes) {
|
||||||
QMetaObject::invokeMethod(_cache.data(), "updateTotalSize", Q_ARG(qint64, _bytes), Q_ARG(qint64, bytes));
|
emit updateSize(bytes - _bytes);
|
||||||
_bytes = bytes;
|
_bytes = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,9 @@ public:
|
||||||
bool isLoaded() const { return _isLoaded; }
|
bool isLoaded() const { return _isLoaded; }
|
||||||
bool isFailed() const { return _isFailed; }
|
bool isFailed() const { return _isFailed; }
|
||||||
|
|
||||||
|
// Connects to a SLOT(updateMemoryCost(qint64) on the given engine
|
||||||
|
void updateMemoryCost(const QObject* engine);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void progressChanged(uint64_t bytesReceived, uint64_t bytesTotal);
|
void progressChanged(uint64_t bytesReceived, uint64_t bytesTotal);
|
||||||
void loadedChanged(bool loaded); // analogous to &Resource::finished
|
void loadedChanged(bool loaded); // analogous to &Resource::finished
|
||||||
|
@ -166,7 +169,7 @@ public slots:
|
||||||
void checkAsynchronousGets();
|
void checkAsynchronousGets();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void updateTotalSize(const qint64& oldSize, const qint64& newSize);
|
void updateTotalSize(const qint64& deltaSize);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void clearATPAssets();
|
void clearATPAssets();
|
||||||
|
@ -291,6 +294,9 @@ signals:
|
||||||
/// Fired when the resource is refreshed.
|
/// Fired when the resource is refreshed.
|
||||||
void onRefresh();
|
void onRefresh();
|
||||||
|
|
||||||
|
/// Fired when the size changes (through setSize).
|
||||||
|
void updateSize(qint64 deltaSize);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void attemptRequest();
|
void attemptRequest();
|
||||||
|
|
||||||
|
@ -333,16 +339,20 @@ private:
|
||||||
void retry();
|
void retry();
|
||||||
void reinsert();
|
void reinsert();
|
||||||
|
|
||||||
|
bool isInScript() const { return _isInScript; }
|
||||||
|
void setInScript(bool isInScript) { _isInScript = isInScript; }
|
||||||
|
|
||||||
friend class ResourceCache;
|
friend class ResourceCache;
|
||||||
friend class ScriptableResource;
|
friend class ScriptableResource;
|
||||||
|
|
||||||
ResourceRequest* _request = nullptr;
|
ResourceRequest* _request{ nullptr };
|
||||||
int _lruKey = 0;
|
int _lruKey{ 0 };
|
||||||
QTimer* _replyTimer = nullptr;
|
QTimer* _replyTimer{ nullptr };
|
||||||
qint64 _bytesReceived = 0;
|
qint64 _bytesReceived{ 0 };
|
||||||
qint64 _bytesTotal = 0;
|
qint64 _bytesTotal{ 0 };
|
||||||
qint64 _bytes = 0;
|
qint64 _bytes{ 0 };
|
||||||
int _attempts = 0;
|
int _attempts{ 0 };
|
||||||
|
bool _isInScript{ false };
|
||||||
};
|
};
|
||||||
|
|
||||||
uint qHash(const QPointer<QObject>& value, uint seed = 0);
|
uint qHash(const QPointer<QObject>& value, uint seed = 0);
|
||||||
|
|
|
@ -274,6 +274,7 @@ static void resultHandlerFromScriptValue(const QScriptValue& value, AnimVariantR
|
||||||
using ScriptableResourceRawPtr = ScriptableResource*;
|
using ScriptableResourceRawPtr = ScriptableResource*;
|
||||||
|
|
||||||
static QScriptValue scriptableResourceToScriptValue(QScriptEngine* engine, const ScriptableResourceRawPtr& resource) {
|
static QScriptValue scriptableResourceToScriptValue(QScriptEngine* engine, const ScriptableResourceRawPtr& resource) {
|
||||||
|
resource->updateMemoryCost(engine);
|
||||||
auto object = engine->newQObject(
|
auto object = engine->newQObject(
|
||||||
const_cast<ScriptableResourceRawPtr>(resource),
|
const_cast<ScriptableResourceRawPtr>(resource),
|
||||||
QScriptEngine::ScriptOwnership);
|
QScriptEngine::ScriptOwnership);
|
||||||
|
@ -809,6 +810,12 @@ void ScriptEngine::callAnimationStateHandler(QScriptValue callback, AnimVariantM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptEngine::updateMemoryCost(const qint64& deltaSize) {
|
||||||
|
if (deltaSize > 0) {
|
||||||
|
reportAdditionalMemoryCost(deltaSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptEngine::timerFired() {
|
void ScriptEngine::timerFired() {
|
||||||
QTimer* callingTimer = reinterpret_cast<QTimer*>(sender());
|
QTimer* callingTimer = reinterpret_cast<QTimer*>(sender());
|
||||||
CallbackData timerData = _timerFunctionMap.value(callingTimer);
|
CallbackData timerData = _timerFunctionMap.value(callingTimer);
|
||||||
|
|
|
@ -158,6 +158,7 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void callAnimationStateHandler(QScriptValue callback, AnimVariantMap parameters, QStringList names, bool useNames, AnimVariantResultHandler resultHandler);
|
void callAnimationStateHandler(QScriptValue callback, AnimVariantMap parameters, QStringList names, bool useNames, AnimVariantResultHandler resultHandler);
|
||||||
|
void updateMemoryCost(const qint64&);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void scriptLoaded(const QString& scriptFilename);
|
void scriptLoaded(const QString& scriptFilename);
|
||||||
|
|
Loading…
Reference in a new issue