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
273class ImageReader : public QRunnable {273class ImageReader : public QRunnable {
274public:274public:
275 275
276 ImageReader(const QWeakPointer<Resource>& texture, const QByteArray& data);276 ImageReader(const QWeakPointer<Resource>& texture, QNetworkReply* reply);
277 277
278 virtual void run();278 virtual void run();
279 279
280private:280private:
281 281
282 QWeakPointer<Resource> _texture;282 QWeakPointer<Resource> _texture;
283 QByteArray _data;283 QNetworkReply* _reply;
284};284};
285 285
286ImageReader::ImageReader(const QWeakPointer<Resource>& texture, const QByteArray& data) :286ImageReader::ImageReader(const QWeakPointer<Resource>& texture, QNetworkReply* reply) :
287 _texture(texture),287 _texture(texture),
288 _data(data) {288 _reply(reply) {
289}289}
290 290
291void ImageReader::run() {291void ImageReader::run() {
292 QSharedPointer<Resource> texture = _texture.toStrongRef();292 QSharedPointer<Resource> texture = _texture.toStrongRef();
293 if (texture.isNull()) {293 if (texture.isNull()) {
294 _reply->deleteLater();
294 return;295 return;
295 }296 }
296 QImage image = QImage::fromData(_data);297 QImage image = QImage::fromData(_reply->readAll());
297 if (image.format() != QImage::Format_ARGB32) {298 if (image.format() != QImage::Format_ARGB32) {
298 image = image.convertToFormat(QImage::Format_ARGB32);299 image = image.convertToFormat(QImage::Format_ARGB32);
299 }300 }
@@ -320,11 +321,12 @@ void ImageReader::run() { · 20 unmodified lines
320 QMetaObject::invokeMethod(texture.data(), "setImage", Q_ARG(const QImage&, image),321 QMetaObject::invokeMethod(texture.data(), "setImage", Q_ARG(const QImage&, image),
321 Q_ARG(const glm::vec4&, accumulated / (imageArea * EIGHT_BIT_MAXIMUM)),322 Q_ARG(const glm::vec4&, accumulated / (imageArea * EIGHT_BIT_MAXIMUM)),
322 Q_ARG(bool, translucentPixels >= imageArea / 2));323 Q_ARG(bool, translucentPixels >= imageArea / 2));
324 _reply->deleteLater();
323}325}
324 326
325void NetworkTexture::downloadFinished(QNetworkReply* reply) {327void NetworkTexture::downloadFinished(QNetworkReply* reply) {
326 // send the reader off to the thread pool328 // 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));
328}330}
329 331
330void NetworkTexture::setImage(const QImage& image, const glm::vec4& averageColor, bool translucent) {332void NetworkTexture::setImage(const QImage& image, const glm::vec4& averageColor, bool translucent) {