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

List:       kde-kimageshop
Subject:    Automatic display update.
From:       Boudewijn Rempt <boud () valdyas ! org>
Date:       2004-03-22 8:33:40
Message-ID: 200403220933.40370.boud () valdyas ! org
[Download RAW message or body]

I took Roger's patch, and moved the relevant code out of the tool and into 
KisImage so all tools can automatically use it. I have added two switches: 
one to enable/disable timer based image repainting, and one to mess with the 
update frequency. Also used a mutex -- without it, you get very funny 
results.

My impression is that it doesn't perform significantly better than direct 
notify(), but in principle it's a sound move to decouple the display updates 
from the code that changes the data. Emacs does it, the Gimp does it...

And it should now be possible to have KisPainter notify the image that rects 
have been dirtied, making it possible to write tools that completely don't 
concern themselves with which parts of the image should be updated.

Anyway, I haven't commited yet -- wanted to first present the patch to y'all:

-- 
Boudewijn Rempt | http://www.valdyas.org/fading/index.cgi

["krita-image-timer.patch" (text/x-diff)]

Index: kis_image.h
===================================================================
RCS file: /home/kde/koffice/krita/core/kis_image.h,v
retrieving revision 1.68
diff -u -3 -u -p -r1.68 kis_image.h
--- kis_image.h	7 Mar 2004 17:05:48 -0000	1.68
+++ kis_image.h	22 Mar 2004 08:33:13 -0000
@@ -23,8 +23,13 @@
 #include <qstring.h>
 #include <qimage.h>
 #include <qvaluevector.h>
+#include <qtimer.h>
+#include <qmutex.h>
+
 #include <kurl.h>
+
 #include <koColor.h>
+
 #include "kis_global.h"
 #include "kis_types.h"
 #include "kis_render.h"
@@ -153,27 +158,40 @@ signals:
 	void visibilityChanged(KisImageSP image, CHANNELTYPE type);
 	void update(KisImageSP image, const QRect& rc);
 
+private slots:
+	void slotUpdateDisplay();
+
 private:
 	KisImage& operator=(const KisImage& rhs);
 	void expand(KisPaintDeviceSP dev);
 	void init(KisUndoAdapter *adapter, Q_INT32 width, Q_INT32 height, const \
enumImgType& imgType, const QString& name);  PIXELTYPE pixelFromChannel(CHANNELTYPE \
type) const;  
+	void startUpdateTimer();
+
 private:
 	KoCommandHistory *m_undoHistory;
 	KURL m_uri;
 	QString m_name;
+
 	Q_INT32 m_width;
 	Q_INT32 m_height;
 	Q_UINT32 m_depth;
+
 	Q_INT32 m_ntileCols;
 	Q_INT32 m_ntileRows;
+
 	double m_xres;
 	double m_yres;
+
 	KoUnit::Unit m_unit;
+
 	enumImgType m_type;
 	KoColorMap m_clrMap;
+
 	bool m_dirty;
+	QRect m_dirtyRect;
+
 	KisTileMgrSP m_shadow;
 	KisBackgroundSP m_bkg;
 	KisLayerSP m_projection;
@@ -193,6 +211,9 @@ private:
 	KisNameServer *m_nserver;
 	KisUndoAdapter *m_adapter;
 	KisGuideMgr m_guides;
+
+	QTimer * m_updateTimer;
+	QMutex m_displayMutex;
 };
 
 #endif // KIS_IMAGE_H_
Index: kis_image.cc
===================================================================
RCS file: /home/kde/koffice/krita/core/kis_image.cc,v
retrieving revision 1.117
diff -u -3 -u -p -r1.117 kis_image.cc
--- kis_image.cc	19 Mar 2004 01:01:39 -0000	1.117
+++ kis_image.cc	22 Mar 2004 08:33:14 -0000
@@ -44,6 +44,13 @@
 #include "visitors/kis_flatten.h"
 
 namespace {
+
+	const bool DISPLAY_TIMER = false; // Whether to repaint the
+					 // display every
+					 // DISPLAY_UPDATE_FREQUENCY
+					 // milliseconds
+	const int DISPLAY_UPDATE_FREQUENCY = 50; // in milliseconds
+
 	class KisResizeImageCmd : public KNamedCommand {
 		typedef KNamedCommand super;
 
@@ -132,6 +139,7 @@ KisImage::KisImage(KisUndoAdapter *undoA
 {
 	init(undoAdapter, width, height, imgType, name);
 	setName(name);
+	startUpdateTimer();
 }
 
 KisImage::KisImage(const KisImage& rhs) : QObject(), KisRenderInterface(rhs)
@@ -161,7 +169,6 @@ KisImage::KisImage(const KisImage& rhs) 
 		m_layers.reserve(rhs.m_layers.size());
 
 		for (vKisLayerSP_cit it = rhs.m_layers.begin(); it != rhs.m_layers.end(); it++) {
-                    kdDebug() << "Adding layers " << endl;
 			KisLayerSP layer = new KisLayer(**it);
 
 			layer -> setImage(KisImageSP(this));
@@ -191,12 +198,15 @@ KisImage::KisImage(const KisImage& rhs) 
 		m_maskClr = rhs.m_maskClr;
 		m_nserver = new KisNameServer(i18n("Layer %1"), rhs.m_nserver -> currentSeed() + \
1);  m_guides = rhs.m_guides;
+		startUpdateTimer();
 	}
+
 }
 
 KisImage::~KisImage()
 {
 	delete m_nserver;
+	// Not necessary to destroy m_updateTimer
 }
 
 QString KisImage::name() const
@@ -1128,8 +1138,7 @@ void KisImage::expand(KisPaintDeviceSP d
 
 void KisImage::notify()
 {
-	invalidate(0, 0, width(), height());
-	emit update(KisImageSP(this), QRect(0, 0, width(), height()));
+	notify(0, 0, width(), height());
 }
 
 void KisImage::notify(Q_INT32 x, Q_INT32 y, Q_INT32 width, Q_INT32 height)
@@ -1139,10 +1148,22 @@ void KisImage::notify(Q_INT32 x, Q_INT32
 
 void KisImage::notify(const QRect& rc)
 {
-    if (rc.isValid()) {
-	invalidate(rc);
-	emit update(KisImageSP(this), rc);
-    }
+	if (DISPLAY_TIMER) {
+		m_displayMutex.lock();
+		if (m_dirtyRect.isValid()) {
+			m_dirtyRect |= rc;
+		} else {
+			m_dirtyRect = rc;
+		}
+		m_displayMutex.unlock();
+	} else {
+		if (rc.isValid()) {
+			invalidate(rc);
+			emit update(KisImageSP(this), rc);
+		}
+	}
+
+ 
 }
 
 QRect KisImage::bounds() const
@@ -1165,5 +1186,27 @@ KisTileMgrSP KisImage::tiles() const
 	return m_projection -> data();
 }
 
+void KisImage::slotUpdateDisplay() 
+{
+	if (m_dirtyRect.isValid()) {
+		m_displayMutex.lock();
+		QRect rect = m_dirtyRect;
+		m_dirtyRect = QRect();
+		m_displayMutex.unlock();
+
+		invalidate(rect);
+		emit update(KisImageSP(this), rect);
+	}
+}
+
+void KisImage::startUpdateTimer() 
+{
+	if (DISPLAY_TIMER) {
+		m_updateTimer = new QTimer(this);
+		connect( m_updateTimer, SIGNAL(timeout()), this, SLOT(slotUpdateDisplay()) );
+		m_updateTimer -> start( DISPLAY_UPDATE_FREQUENCY );
+	}
+}
+
 #include "kis_image.moc"
 



_______________________________________________
kimageshop mailing list
kimageshop@kde.org
https://mail.kde.org/mailman/listinfo/kimageshop


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

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