Remove delayLoad

This commit is contained in:
Zach Pomerantz 2016-05-09 18:01:21 -07:00
parent 9ac783a88d
commit 09d879e19f
14 changed files with 50 additions and 53 deletions

View file

@ -36,7 +36,7 @@ AnimationPointer AnimationCache::getAnimation(const QUrl& url) {
} }
QSharedPointer<Resource> AnimationCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, QSharedPointer<Resource> AnimationCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
bool delayLoad, const void* extra) { const void* extra) {
return QSharedPointer<Resource>(new Animation(url), &Resource::deleter); return QSharedPointer<Resource>(new Animation(url), &Resource::deleter);
} }

View file

@ -35,8 +35,8 @@ public:
protected: protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url, virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra); const void* extra);
private: private:
explicit AnimationCache(QObject* parent = NULL); explicit AnimationCache(QObject* parent = NULL);
virtual ~AnimationCache() { } virtual ~AnimationCache() { }

View file

@ -35,7 +35,7 @@ SharedSoundPointer SoundCache::getSound(const QUrl& url) {
} }
QSharedPointer<Resource> SoundCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, QSharedPointer<Resource> SoundCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
bool delayLoad, const void* extra) { const void* extra) {
qCDebug(audio) << "Requesting sound at" << url.toString(); qCDebug(audio) << "Requesting sound at" << url.toString();
return QSharedPointer<Resource>(new Sound(url), &Resource::deleter); return QSharedPointer<Resource>(new Sound(url), &Resource::deleter);
} }

View file

@ -25,8 +25,8 @@ public:
Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url); Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url);
protected: protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url, virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra); const void* extra);
private: private:
SoundCache(QObject* parent = NULL); SoundCache(QObject* parent = NULL);
}; };

View file

@ -71,7 +71,7 @@ void GeometryMappingResource::downloadFinished(const QByteArray& data) {
GeometryExtra extra{ mapping, _textureBaseUrl }; GeometryExtra extra{ mapping, _textureBaseUrl };
// Get the raw GeometryResource, not the wrapped NetworkGeometry // Get the raw GeometryResource, not the wrapped NetworkGeometry
_geometryResource = modelCache->getResource(url, QUrl(), false, &extra).staticCast<GeometryResource>(); _geometryResource = modelCache->getResource(url, QUrl(), &extra).staticCast<GeometryResource>();
// Avoid caching nested resources - their references will be held by the parent // Avoid caching nested resources - their references will be held by the parent
_geometryResource->_isCacheable = false; _geometryResource->_isCacheable = false;
@ -236,7 +236,7 @@ ModelCache::ModelCache() {
} }
QSharedPointer<Resource> ModelCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, QSharedPointer<Resource> ModelCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
bool delayLoad, const void* extra) { const void* extra) {
Resource* resource = nullptr; Resource* resource = nullptr;
if (url.path().toLower().endsWith(".fst")) { if (url.path().toLower().endsWith(".fst")) {
resource = new GeometryMappingResource(url); resource = new GeometryMappingResource(url);
@ -252,7 +252,7 @@ QSharedPointer<Resource> ModelCache::createResource(const QUrl& url, const QShar
std::shared_ptr<NetworkGeometry> ModelCache::getGeometry(const QUrl& url, const QVariantHash& mapping, const QUrl& textureBaseUrl) { std::shared_ptr<NetworkGeometry> ModelCache::getGeometry(const QUrl& url, const QVariantHash& mapping, const QUrl& textureBaseUrl) {
GeometryExtra geometryExtra = { mapping, textureBaseUrl }; GeometryExtra geometryExtra = { mapping, textureBaseUrl };
GeometryResource::Pointer resource = getResource(url, QUrl(), true, &geometryExtra).staticCast<GeometryResource>(); GeometryResource::Pointer resource = getResource(url, QUrl(), &geometryExtra).staticCast<GeometryResource>();
if (resource) { if (resource) {
if (resource->isLoaded() && resource->shouldSetTextures()) { if (resource->isLoaded() && resource->shouldSetTextures()) {
resource->setTextures(); resource->setTextures();

View file

@ -44,8 +44,8 @@ public:
protected: protected:
friend class GeometryMappingResource; friend class GeometryMappingResource;
virtual QSharedPointer<Resource> createResource(const QUrl& url, virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra); const void* extra);
private: private:
ModelCache(); ModelCache();

View file

@ -7,11 +7,8 @@
// //
#include "ShaderCache.h" #include "ShaderCache.h"
NetworkShader::NetworkShader(const QUrl& url, bool delayLoad) NetworkShader::NetworkShader(const QUrl& url) :
: Resource(url, delayLoad) Resource(url) {}
{
}
void NetworkShader::downloadFinished(const QByteArray& data) { void NetworkShader::downloadFinished(const QByteArray& data) {
_source = QString::fromUtf8(data); _source = QString::fromUtf8(data);
@ -24,10 +21,11 @@ ShaderCache& ShaderCache::instance() {
} }
NetworkShaderPointer ShaderCache::getShader(const QUrl& url) { NetworkShaderPointer ShaderCache::getShader(const QUrl& url) {
return ResourceCache::getResource(url, QUrl(), false, nullptr).staticCast<NetworkShader>(); return ResourceCache::getResource(url, QUrl(), nullptr).staticCast<NetworkShader>();
} }
QSharedPointer<Resource> ShaderCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra) { QSharedPointer<Resource> ShaderCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
return QSharedPointer<Resource>(new NetworkShader(url, delayLoad), &Resource::deleter); const void* extra) {
return QSharedPointer<Resource>(new NetworkShader(url), &Resource::deleter);
} }

View file

@ -13,7 +13,7 @@
class NetworkShader : public Resource { class NetworkShader : public Resource {
public: public:
NetworkShader(const QUrl& url, bool delayLoad); NetworkShader(const QUrl& url);
virtual void downloadFinished(const QByteArray& data) override; virtual void downloadFinished(const QByteArray& data) override;
QString _source; QString _source;
@ -28,7 +28,8 @@ public:
NetworkShaderPointer getShader(const QUrl& url); NetworkShaderPointer getShader(const QUrl& url);
protected: protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra) override; virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const void* extra) override;
}; };
#endif #endif

View file

@ -167,7 +167,7 @@ ScriptableResource* TextureCache::prefetch(const QUrl& url, int type) {
NetworkTexturePointer TextureCache::getTexture(const QUrl& url, Type type, const QByteArray& content) { NetworkTexturePointer TextureCache::getTexture(const QUrl& url, Type type, const QByteArray& content) {
TextureExtra extra = { type, content }; TextureExtra extra = { type, content };
return ResourceCache::getResource(url, QUrl(), content.isEmpty(), &extra).staticCast<NetworkTexture>(); return ResourceCache::getResource(url, QUrl(), &extra).staticCast<NetworkTexture>();
} }
@ -231,8 +231,8 @@ gpu::TexturePointer TextureCache::getImageTexture(const QString& path, Type type
return gpu::TexturePointer(loader(image, QUrl::fromLocalFile(path).fileName().toStdString())); return gpu::TexturePointer(loader(image, QUrl::fromLocalFile(path).fileName().toStdString()));
} }
QSharedPointer<Resource> TextureCache::createResource(const QUrl& url, QSharedPointer<Resource> TextureCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra) { const void* extra) {
const TextureExtra* textureExtra = static_cast<const TextureExtra*>(extra); const TextureExtra* textureExtra = static_cast<const TextureExtra*>(extra);
auto type = textureExtra ? textureExtra->type : Type::DEFAULT_TEXTURE; auto type = textureExtra ? textureExtra->type : Type::DEFAULT_TEXTURE;
auto content = textureExtra ? textureExtra->content : QByteArray(); auto content = textureExtra ? textureExtra->content : QByteArray();
@ -241,7 +241,7 @@ QSharedPointer<Resource> TextureCache::createResource(const QUrl& url,
} }
NetworkTexture::NetworkTexture(const QUrl& url, Type type, const QByteArray& content) : NetworkTexture::NetworkTexture(const QUrl& url, Type type, const QByteArray& content) :
Resource(url, !content.isEmpty()), Resource(url),
_type(type) _type(type)
{ {
_textureSource = std::make_shared<gpu::TextureSource>(); _textureSource = std::make_shared<gpu::TextureSource>();

View file

@ -131,8 +131,8 @@ protected:
// Overload ResourceCache::prefetch to allow specifying texture type for loads // Overload ResourceCache::prefetch to allow specifying texture type for loads
Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type); Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type);
virtual QSharedPointer<Resource> createResource(const QUrl& url, virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra); const void* extra);
private: private:
TextureCache(); TextureCache();

View file

@ -179,7 +179,7 @@ ScriptableResource* ResourceCache::prefetch(const QUrl& url, void* extra) {
result = new ScriptableResource(url); result = new ScriptableResource(url);
auto resource = getResource(url, QUrl(), false, extra); auto resource = getResource(url, QUrl(), extra);
result->_resource = resource; result->_resource = resource;
result->setObjectName(url.toString()); result->setObjectName(url.toString());
@ -316,8 +316,7 @@ void ResourceCache::setRequestLimit(int limit) {
} }
} }
QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl& fallback, QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl& fallback, void* extra) {
bool delayLoad, void* extra) {
QSharedPointer<Resource> resource; QSharedPointer<Resource> resource;
{ {
QReadLocker locker(&_resourcesLock); QReadLocker locker(&_resourcesLock);
@ -330,19 +329,20 @@ QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl&
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
qCDebug(networking) << "Fetching asynchronously:" << url; qCDebug(networking) << "Fetching asynchronously:" << url;
assert(delayLoad);
QMetaObject::invokeMethod(this, "getResource", QMetaObject::invokeMethod(this, "getResource",
Q_ARG(QUrl, url), Q_ARG(QUrl, fallback), Q_ARG(bool, delayLoad)); Q_ARG(QUrl, url), Q_ARG(QUrl, fallback));
// Cannot use extra parameter as it might be freed before the invocation // Cannot use extra parameter as it might be freed before the invocation
return QSharedPointer<Resource>(); return QSharedPointer<Resource>();
} }
if (!url.isValid() && !url.isEmpty() && fallback.isValid()) { if (!url.isValid() && !url.isEmpty() && fallback.isValid()) {
return getResource(fallback, QUrl(), delayLoad); return getResource(fallback, QUrl());
} }
resource = createResource(url, fallback.isValid() ? resource = createResource(
getResource(fallback, QUrl(), true) : QSharedPointer<Resource>(), delayLoad, extra); url,
fallback.isValid() ? getResource(fallback, QUrl()) : QSharedPointer<Resource>(),
extra);
resource->setSelf(resource); resource->setSelf(resource);
resource->setCache(this); resource->setCache(this);
connect(resource.data(), &Resource::updateSize, this, &ResourceCache::updateTotalSize); connect(resource.data(), &Resource::updateSize, this, &ResourceCache::updateTotalSize);
@ -494,7 +494,7 @@ const int DEFAULT_REQUEST_LIMIT = 10;
int ResourceCache::_requestLimit = DEFAULT_REQUEST_LIMIT; int ResourceCache::_requestLimit = DEFAULT_REQUEST_LIMIT;
int ResourceCache::_requestsActive = 0; int ResourceCache::_requestsActive = 0;
Resource::Resource(const QUrl& url, bool delayLoad) : Resource::Resource(const QUrl& url) :
_url(url), _url(url),
_activeUrl(url), _activeUrl(url),
_request(nullptr) { _request(nullptr) {

View file

@ -187,12 +187,13 @@ protected slots:
// and delegate to it (see TextureCache::prefetch(const QUrl&, int). // and delegate to it (see TextureCache::prefetch(const QUrl&, int).
ScriptableResource* prefetch(const QUrl& url, void* extra); ScriptableResource* prefetch(const QUrl& url, void* extra);
/// Loads a resource from the specified URL. /// Loads a resource from the specified URL and returns it.
/// If the caller is on a different thread than the ResourceCache,
/// returns an empty smart pointer and loads its asynchronously.
/// \param fallback a fallback URL to load if the desired one is unavailable /// \param fallback a fallback URL to load if the desired one is unavailable
/// \param delayLoad if true, don't load the resource immediately; wait until load is first requested
/// \param extra extra data to pass to the creator, if appropriate /// \param extra extra data to pass to the creator, if appropriate
QSharedPointer<Resource> getResource(const QUrl& url, const QUrl& fallback = QUrl(), QSharedPointer<Resource> getResource(const QUrl& url, const QUrl& fallback = QUrl(),
bool delayLoad = false, void* extra = NULL); void* extra = NULL);
private slots: private slots:
void clearATPAssets(); void clearATPAssets();
@ -205,8 +206,8 @@ protected:
Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url) { return prefetch(url, nullptr); } Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url) { return prefetch(url, nullptr); }
/// Creates a new resource. /// Creates a new resource.
virtual QSharedPointer<Resource> createResource(const QUrl& url, virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra) = 0; const void* extra) = 0;
void addUnusedResource(const QSharedPointer<Resource>& resource); void addUnusedResource(const QSharedPointer<Resource>& resource);
void removeUnusedResource(const QSharedPointer<Resource>& resource); void removeUnusedResource(const QSharedPointer<Resource>& resource);
@ -257,7 +258,7 @@ class Resource : public QObject {
public: public:
Resource(const QUrl& url, bool delayLoad = false); Resource(const QUrl& url);
~Resource(); ~Resource();
/// Returns the key last used to identify this resource in the unused map. /// Returns the key last used to identify this resource in the unused map.

View file

@ -9,12 +9,9 @@
#include "impl/PointerClip.h" #include "impl/PointerClip.h"
using namespace recording; using namespace recording;
NetworkClipLoader::NetworkClipLoader(const QUrl& url, bool delayLoad) NetworkClipLoader::NetworkClipLoader(const QUrl& url) :
: Resource(url, delayLoad), _clip(std::make_shared<NetworkClip>(url)) Resource(url),
{ _clip(std::make_shared<NetworkClip>(url)) {}
}
void NetworkClip::init(const QByteArray& clipData) { void NetworkClip::init(const QByteArray& clipData) {
_clipData = clipData; _clipData = clipData;
@ -32,10 +29,10 @@ ClipCache& ClipCache::instance() {
} }
NetworkClipLoaderPointer ClipCache::getClipLoader(const QUrl& url) { NetworkClipLoaderPointer ClipCache::getClipLoader(const QUrl& url) {
return ResourceCache::getResource(url, QUrl(), false, nullptr).staticCast<NetworkClipLoader>(); return ResourceCache::getResource(url, QUrl(), nullptr).staticCast<NetworkClipLoader>();
} }
QSharedPointer<Resource> ClipCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra) { QSharedPointer<Resource> ClipCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, const void* extra) {
return QSharedPointer<Resource>(new NetworkClipLoader(url, delayLoad), &Resource::deleter); return QSharedPointer<Resource>(new NetworkClipLoader(url), &Resource::deleter);
} }

View file

@ -31,7 +31,7 @@ private:
class NetworkClipLoader : public Resource { class NetworkClipLoader : public Resource {
public: public:
NetworkClipLoader(const QUrl& url, bool delayLoad); NetworkClipLoader(const QUrl& url);
virtual void downloadFinished(const QByteArray& data) override; virtual void downloadFinished(const QByteArray& data) override;
ClipPointer getClip() { return _clip; } ClipPointer getClip() { return _clip; }
bool completed() { return _failedToLoad || isLoaded(); } bool completed() { return _failedToLoad || isLoaded(); }
@ -49,7 +49,7 @@ public:
NetworkClipLoaderPointer getClipLoader(const QUrl& url); NetworkClipLoaderPointer getClipLoader(const QUrl& url);
protected: protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra) override; virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, const void* extra) override;
}; };
} }