[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegames/kpat/libkcardgame
From:       Parker Coates <parker.coates () kdemail ! net>
Date:       2010-09-13 0:37:03
Message-ID: 20100913003703.7A81BAC88C () svn ! kde ! org
[Download RAW message or body]

SVN commit 1174621 by coates:

Fix a false caching assumption.

Before we assumed that an image placed in the cache by the rendering
thread would still be there when needed. This obviously isn't always
true, so once in a while a card would fail to get an updated pixmap.

 M  +11 -6     kabstractcarddeck.cpp  
 M  +2 -2      kabstractcarddeck_p.h  


--- trunk/KDE/kdegames/kpat/libkcardgame/kabstractcarddeck.cpp #1174620:1174621
@@ -53,7 +53,7 @@
     m_elementsToRender( elements ),
     m_haltFlag( false )
 {
-    connect( this, SIGNAL(renderingDone(QString)), d, \
SLOT(submitRendering(QString)), Qt::QueuedConnection ); +    connect( this, \
SIGNAL(renderingDone(QString,QImage)), d, SLOT(submitRendering(QString,QImage)), \
Qt::QueuedConnection );  }
 
 
@@ -99,7 +99,7 @@
 
             d->cache->insertImage( key, img );
 
-            emit renderingDone( element );
+            emit renderingDone( element, img );
         }
     }
 }
@@ -237,11 +237,17 @@
 }
 
 
-void KAbstractCardDeckPrivate::submitRendering( const QString & elementId )
+void KAbstractCardDeckPrivate::submitRendering( const QString & elementId, const \
QImage & image )  {
     QPixmap pix;
-    if ( cache->findPixmap( keyForPixmap( elementId, currentCardSize ), &pix ) )
-    {
+
+    // The RenderingThread just put the image in the cache, but due to the
+    // volatility of the cache there's no guarantee that it'll still be there
+    // by the time this slot is called, in which case we convert the QImage
+    // passed in the signal.
+    if ( !cache->findPixmap( keyForPixmap( elementId, currentCardSize ), &pix ) )
+        pix = QPixmap::fromImage( image );
+
         QHash<QString,CardElementData>::iterator it;
         it = frontIndex.find( elementId );
         if ( it != frontIndex.end() )
@@ -259,7 +265,6 @@
                 c->setBackPixmap( pix );
         }
     }
-}
 
 
 void KAbstractCardDeckPrivate::cardStartedAnimation( KCard * card )
--- trunk/KDE/kdegames/kpat/libkcardgame/kabstractcarddeck_p.h #1174620:1174621
@@ -46,7 +46,7 @@
     void halt();
 
 Q_SIGNALS:
-    void renderingDone( const QString & elementId );
+    void renderingDone( const QString & elementId, const QImage & image );
 
 private:
     KAbstractCardDeckPrivate * const d;
@@ -80,7 +80,7 @@
     void deleteThread();
 
 public Q_SLOTS:
-    void submitRendering( const QString & elementId );
+    void submitRendering( const QString & elementId, const QImage & image );
     void cardStartedAnimation( KCard * card );
     void cardStoppedAnimation( KCard * card );
     void checkIfAnimationIsDone();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic