History

Do the actual reading of the reply on the worker thread. Otherwise, when we read from the cache, we're reading synchronously from a file. Closes #2171.

Andrzej Kapolka committed 12 years ago

Commit 7ecfeea1 parent 9759cd75 files · +20 −16Browse files

Showing the changes to interface/src/renderer/TextureCache.cpp (1 of 5 files). Show all

Unified · Split

interface/src/renderer/TextureCache.cpp+8−6
@@ -273,27 +273,28 @@ NetworkTexture::NetworkTexture(const QUrl& url, bool normalMap) : · 272 unmodified lines
273273 class ImageReader : public QRunnable {
274274 public:
275275
276− ImageReader(const QWeakPointer<Resource>& texture, const QByteArray& data);
276+ ImageReader(const QWeakPointer<Resource>& texture, QNetworkReply* reply);
277277
278278 virtual void run();
279279
280280 private:
281281
282282 QWeakPointer<Resource> _texture;
283− QByteArray _data;
283+ QNetworkReply* _reply;
284284 };
285285
286−ImageReader::ImageReader(const QWeakPointer<Resource>& texture, const QByteArray& data) :
286+ImageReader::ImageReader(const QWeakPointer<Resource>& texture, QNetworkReply* reply) :
287287 _texture(texture),
288− _data(data) {
288+ _reply(reply) {
289289 }
290290
291291 void ImageReader::run() {
292292 QSharedPointer<Resource> texture = _texture.toStrongRef();
293293 if (texture.isNull()) {
294+ _reply->deleteLater();
294295 return;
295296 }
296− QImage image = QImage::fromData(_data);
297+ QImage image = QImage::fromData(_reply->readAll());
297298 if (image.format() != QImage::Format_ARGB32) {
298299 image = image.convertToFormat(QImage::Format_ARGB32);
299300 }
@@ -320,11 +321,12 @@ void ImageReader::run() { · 20 unmodified lines
320321 QMetaObject::invokeMethod(texture.data(), "setImage", Q_ARG(const QImage&, image),
321322 Q_ARG(const glm::vec4&, accumulated / (imageArea * EIGHT_BIT_MAXIMUM)),
322323 Q_ARG(bool, translucentPixels >= imageArea / 2));
324+ _reply->deleteLater();
323325 }
324326
325327 void NetworkTexture::downloadFinished(QNetworkReply* reply) {
326328 // send the reader off to the thread pool
327− QThreadPool::globalInstance()->start(new ImageReader(_self, reply->readAll()));
329+ QThreadPool::globalInstance()->start(new ImageReader(_self, reply));
328330 }
329331
330332 void NetworkTexture::setImage(const QImage& image, const glm::vec4& averageColor, bool translucent) {