Changeset View
Changeset View
Standalone View
Standalone View
libkcardgame/kabstractcarddeck.cpp
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | |||||
70 | void RenderingThread::run() | 70 | void RenderingThread::run() | ||
71 | { | 71 | { | ||
72 | { | 72 | { | ||
73 | // Load the renderer even if we don't have any elements to render. | 73 | // Load the renderer even if we don't have any elements to render. | ||
74 | QMutexLocker l( &(d->rendererMutex) ); | 74 | QMutexLocker l( &(d->rendererMutex) ); | ||
75 | d->renderer(); | 75 | d->renderer(); | ||
76 | } | 76 | } | ||
77 | 77 | | |||
78 | const auto size = m_size * qApp->devicePixelRatio(); | ||||
78 | foreach ( const QString & element, m_elementsToRender ) | 79 | foreach ( const QString & element, m_elementsToRender ) | ||
79 | { | 80 | { | ||
80 | { | 81 | { | ||
81 | QMutexLocker l( &m_haltMutex ); | 82 | QMutexLocker l( &m_haltMutex ); | ||
82 | if ( m_haltFlag ) | 83 | if ( m_haltFlag ) | ||
83 | return; | 84 | return; | ||
84 | } | 85 | } | ||
85 | 86 | | |||
86 | QString key = keyForPixmap( element, m_size ); | 87 | QString key = keyForPixmap( element, size ); | ||
87 | if ( !d->cache->contains( key ) ) | 88 | if ( !d->cache->contains( key ) ) | ||
88 | { | 89 | { | ||
89 | //qCDebug(LIBKCARDGAME_LOG) << "Renderering" << key << "in rendering thread."; | 90 | //qCDebug(LIBKCARDGAME_LOG) << "Renderering" << key << "in rendering thread."; | ||
90 | QImage img = d->renderCard( element, m_size ); | 91 | QImage img = d->renderCard( element, size ); | ||
91 | d->cache->insertImage( key, img ); | 92 | d->cache->insertImage( key, img ); | ||
92 | emit renderingDone( element, img ); | 93 | emit renderingDone( element, img ); | ||
93 | } | 94 | } | ||
94 | } | 95 | } | ||
95 | } | 96 | } | ||
96 | 97 | | |||
97 | 98 | | |||
98 | KAbstractCardDeckPrivate::KAbstractCardDeckPrivate( KAbstractCardDeck * q ) | 99 | KAbstractCardDeckPrivate::KAbstractCardDeckPrivate( KAbstractCardDeck * q ) | ||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | 189 | { | |||
192 | QString elementId = q->elementName( id, faceUp ); | 193 | QString elementId = q->elementName( id, faceUp ); | ||
193 | QHash<QString,CardElementData> & index = faceUp ? frontIndex : backIndex; | 194 | QHash<QString,CardElementData> & index = faceUp ? frontIndex : backIndex; | ||
194 | 195 | | |||
195 | QHash<QString,CardElementData>::iterator it = index.find( elementId ); | 196 | QHash<QString,CardElementData>::iterator it = index.find( elementId ); | ||
196 | if ( it == index.end() ) | 197 | if ( it == index.end() ) | ||
197 | return QPixmap(); | 198 | return QPixmap(); | ||
198 | 199 | | |||
199 | QPixmap & stored = it.value().cardPixmap; | 200 | QPixmap & stored = it.value().cardPixmap; | ||
200 | if ( stored.size() != currentCardSize ) | 201 | const auto dpr = qApp->devicePixelRatio(); | ||
202 | QSize requestedCardSize = currentCardSize * dpr; | ||||
203 | if ( stored.size() != requestedCardSize ) | ||||
201 | { | 204 | { | ||
202 | QString key = keyForPixmap( elementId , currentCardSize ); | 205 | QString key = keyForPixmap( elementId , requestedCardSize ); | ||
203 | if ( !cache->findPixmap( key, &stored ) ) | 206 | if ( !cache->findPixmap( key, &stored ) ) | ||
204 | { | 207 | { | ||
205 | if ( stored.isNull() ) | 208 | if ( stored.isNull() ) | ||
206 | { | 209 | { | ||
207 | //qCDebug(LIBKCARDGAME_LOG) << "Renderering" << key << "in main thread."; | 210 | //qCDebug(LIBKCARDGAME_LOG) << "Renderering" << key << "in main thread."; | ||
208 | QImage img = renderCard( elementId, currentCardSize ); | 211 | QImage img = renderCard( elementId, requestedCardSize ); | ||
209 | cache->insertImage( key, img ); | 212 | cache->insertImage( key, img ); | ||
210 | stored = QPixmap::fromImage( img ); | 213 | stored = QPixmap::fromImage( img ); | ||
211 | } | 214 | } | ||
212 | else | 215 | else | ||
213 | { | 216 | { | ||
214 | stored = stored.scaled( currentCardSize ); | 217 | stored = stored.scaled( requestedCardSize ); | ||
215 | } | 218 | } | ||
216 | } | 219 | } | ||
217 | Q_ASSERT( stored.size() == currentCardSize ); | 220 | Q_ASSERT( stored.size() == requestedCardSize ); | ||
221 | stored.setDevicePixelRatio( dpr ); | ||||
218 | } | 222 | } | ||
219 | return stored; | 223 | return stored; | ||
220 | } | 224 | } | ||
221 | 225 | | |||
222 | 226 | | |||
223 | void KAbstractCardDeckPrivate::deleteThread() | 227 | void KAbstractCardDeckPrivate::deleteThread() | ||
224 | { | 228 | { | ||
225 | if ( thread && thread->isRunning() ) | 229 | if ( thread && thread->isRunning() ) | ||
226 | thread->halt(); | 230 | thread->halt(); | ||
227 | delete thread; | 231 | delete thread; | ||
228 | thread = nullptr; | 232 | thread = nullptr; | ||
229 | } | 233 | } | ||
230 | 234 | | |||
231 | 235 | | |||
232 | void KAbstractCardDeckPrivate::submitRendering( const QString & elementId, const QImage & image ) | 236 | void KAbstractCardDeckPrivate::submitRendering( const QString & elementId, const QImage & image ) | ||
233 | { | 237 | { | ||
234 | QPixmap pix; | 238 | QPixmap pix; | ||
235 | 239 | | |||
236 | // If the currentCardSize has changed since the rendering was performed, | 240 | // If the currentCardSize has changed since the rendering was performed, | ||
237 | // we sadly just have to throw it away. | 241 | // we sadly just have to throw it away. | ||
238 | if ( image.size() != currentCardSize ) | 242 | const auto dpr = qApp->devicePixelRatio(); | ||
243 | if ( image.size() != currentCardSize * dpr) | ||||
239 | return; | 244 | return; | ||
240 | 245 | | |||
241 | // The RenderingThread just put the image in the cache, but due to the | 246 | // The RenderingThread just put the image in the cache, but due to the | ||
242 | // volatility of the cache there's no guarantee that it'll still be there | 247 | // volatility of the cache there's no guarantee that it'll still be there | ||
243 | // by the time this slot is called, in which case we convert the QImage | 248 | // by the time this slot is called, in which case we convert the QImage | ||
244 | // passed in the signal. | 249 | // passed in the signal. | ||
245 | if ( !cache->findPixmap( keyForPixmap( elementId, currentCardSize ), &pix ) ) | 250 | if ( !cache->findPixmap( keyForPixmap( elementId, currentCardSize * dpr ), &pix ) ) | ||
246 | pix = QPixmap::fromImage( image ); | 251 | pix = QPixmap::fromImage( image ); | ||
247 | 252 | | |||
253 | pix.setDevicePixelRatio( dpr ); | ||||
254 | | ||||
248 | QHash<QString,CardElementData>::iterator it; | 255 | QHash<QString,CardElementData>::iterator it; | ||
249 | it = frontIndex.find( elementId ); | 256 | it = frontIndex.find( elementId ); | ||
250 | if ( it != frontIndex.end() ) | 257 | if ( it != frontIndex.end() ) | ||
251 | { | 258 | { | ||
252 | it.value().cardPixmap = pix; | 259 | it.value().cardPixmap = pix; | ||
253 | foreach ( KCard * c, it.value().cardUsers ) | 260 | foreach ( KCard * c, it.value().cardUsers ) | ||
254 | c->setFrontPixmap( pix ); | 261 | c->setFrontPixmap( pix ); | ||
255 | } | 262 | } | ||
▲ Show 20 Lines • Show All 253 Lines • Show Last 20 Lines |