diff --git a/kgamerenderer.cpp b/kgamerenderer.cpp --- a/kgamerenderer.cpp +++ b/kgamerenderer.cpp @@ -411,7 +411,7 @@ QPixmap KGameRenderer::spritePixmap(const QString& key, const QSize& size, int frame, const QHash& customColors) const { QPixmap result; - d->requestPixmap(KGRInternal::ClientSpec(key, frame, size, customColors), 0, &result); + d->requestPixmap(KGRInternal::ClientSpec(key, frame, size, 1.0, customColors), 0, &result); return result; } @@ -438,7 +438,8 @@ return; } const QString elementKey = spriteFrameKey(spec.spriteKey, spec.frame); - QString cacheKey = m_sizePrefix.arg(spec.size.width()).arg(spec.size.height()) + elementKey; + const QSize size = spec.size * spec.devicePixelRatio; + QString cacheKey = m_sizePrefix.arg(size.width()).arg(size.height()) + elementKey; QHash::const_iterator it1 = spec.customColors.constBegin(), it2 = spec.customColors.constEnd(); static const QString colorSuffix(QStringLiteral( "-%1-%2" )); for (; it1 != it2; ++it1) @@ -463,15 +464,18 @@ QHash::const_iterator it = m_pixmapCache.constFind(cacheKey); if (it != m_pixmapCache.constEnd()) { - requestPixmap__propagateResult(it.value(), client, synchronousResult); + auto pix = it.value(); + pix.setDevicePixelRatio(spec.devicePixelRatio); + requestPixmap__propagateResult(pix, client, synchronousResult); return; } //try to serve from low-speed cache if (m_strategies & KGameRenderer::UseDiskCache) { QPixmap pix; if (m_imageCache->findPixmap(cacheKey, &pix)) { + pix.setDevicePixelRatio(spec.devicePixelRatio); m_pixmapCache.insert(cacheKey, pix); requestPixmap__propagateResult(pix, client, synchronousResult); return; @@ -524,10 +528,11 @@ return; } } - const QPixmap pixmap = QPixmap::fromImage(result); + QPixmap pixmap = QPixmap::fromImage(result); m_pixmapCache.insert(cacheKey, pixmap); foreach (KGameRendererClient* requester, requesters) { + pixmap.setDevicePixelRatio(requester->devicePixelRatio()); requester->receivePixmap(pixmap); } } @@ -545,7 +550,8 @@ void KGRInternal::Worker::run() { - QImage image(m_job->spec.size, QImage::Format_ARGB32_Premultiplied); + const auto dpr = m_job->spec.devicePixelRatio; + QImage image(m_job->spec.size * dpr, QImage::Format_ARGB32_Premultiplied); image.fill(transparentRgba); QPainter* painter = 0; QPaintDeviceColorProxy* proxy = 0; @@ -568,6 +574,7 @@ delete proxy; //talk back to the main thread + image.setDevicePixelRatio(dpr); m_job->result = image; QMetaObject::invokeMethod( m_parent, "jobFinished", Qt::AutoConnection, diff --git a/kgamerenderer_p.h b/kgamerenderer_p.h --- a/kgamerenderer_p.h +++ b/kgamerenderer_p.h @@ -34,16 +34,18 @@ { // The parentheses around QHash() avoid compile // errors on platforms with older gcc versions, e.g. OS X 10.6. - inline ClientSpec(const QString& spriteKey = QString(), int frame = -1, const QSize& size = QSize(), const QHash& customColors = (QHash())); + inline ClientSpec(const QString& spriteKey = QString(), int frame = -1, const QSize& size = QSize(), qreal devicePixelRatio = 1.0, const QHash& customColors = (QHash())); QString spriteKey; int frame; QSize size; + qreal devicePixelRatio; QHash customColors; }; - ClientSpec::ClientSpec(const QString& spriteKey_, int frame_, const QSize& size_, const QHash& customColors_) + ClientSpec::ClientSpec(const QString& spriteKey_, int frame_, const QSize& size_, qreal devicePixelRatio_, const QHash& customColors_) : spriteKey(spriteKey_) , frame(frame_) , size(size_) + , devicePixelRatio(devicePixelRatio_) , customColors(customColors_) { } diff --git a/kgamerendererclient.h b/kgamerendererclient.h --- a/kgamerendererclient.h +++ b/kgamerendererclient.h @@ -88,6 +88,11 @@ ///The default render size is very small (width = height = 3 pixels), so ///that you notice when you forget to set this. ;-) void setRenderSize(const QSize& renderSize); + ///@return the device pixel ratio of the pixmap requested from KGameRenderer + qreal devicePixelRatio() const; + ///Defines the device pixel ratio of the pixmap that will be requested from + ///KGameRenderer. + void setDevicePixelRatio(qreal dpr); ///@return the custom color replacements for this client QHash customColors() const; ///Defines the custom color replacements for this client. That is, for diff --git a/kgamerendererclient.cpp b/kgamerendererclient.cpp --- a/kgamerendererclient.cpp +++ b/kgamerendererclient.cpp @@ -109,6 +109,16 @@ } } +qreal KGameRendererClient::devicePixelRatio() const +{ + return d->m_spec.devicePixelRatio; +} + +void KGameRendererClient::setDevicePixelRatio(qreal dpr) +{ + d->m_spec.devicePixelRatio = dpr; +} + QHash KGameRendererClient::customColors() const { return d->m_spec.customColors;