Commit 1f451cfb authored by Halla Rempt's avatar Halla Rempt

Change QRegion to QRect in KisIndirectPaintSupport

Instead of adding a rect to a region for every dab, we coalesce the
footprints into a big rect. This makes painting faster, but at the end
of the stroke we do much more work since we bitBlt the whole united
rect to the target layer, instead of just the rects the stroke touched.

Note: we might be able to remove the mutex, too.
parent c5a50fb0
......@@ -37,9 +37,8 @@ struct KisIndirectPaintingSupport::Private {
quint8 compositeOpacity;
QBitArray channelFlags;
QReadWriteLock lock;
QMutex dirtyRegionMutex;
QRegion dirtyRegion;
QRect dirtyRegion;
};
......@@ -56,7 +55,7 @@ KisIndirectPaintingSupport::~KisIndirectPaintingSupport()
void KisIndirectPaintingSupport::setTemporaryTarget(KisPaintDeviceSP t)
{
d->dirtyRegion = QRegion();
d->dirtyRegion = QRect();
d->temporaryTarget = t;
}
......@@ -118,23 +117,13 @@ bool KisIndirectPaintingSupport::hasTemporaryTarget() const
void KisIndirectPaintingSupport::setDirty(const QRect &rect)
{
lockTemporaryTarget();
if(hasTemporaryTarget()) {
addIndirectlyDirtyRect(rect);
if (hasTemporaryTarget()) {
QMutexLocker locker(&d->dirtyRegionMutex);
d->dirtyRegion |= rect;
}
unlockTemporaryTarget();
}
void KisIndirectPaintingSupport::addIndirectlyDirtyRect(const QRect &rect)
{
QMutexLocker locker(&d->dirtyRegionMutex);
d->dirtyRegion += rect;
}
QRegion KisIndirectPaintingSupport::indirectlyDirtyRegion()
{
QMutexLocker locker(&d->dirtyRegionMutex);
return d->dirtyRegion;
}
void KisIndirectPaintingSupport::mergeToLayer(KisLayerSP layer, KisUndoAdapter *undoAdapter, const QString &transactionText)
{
......@@ -168,10 +157,9 @@ void KisIndirectPaintingSupport::mergeToLayerImpl(KisLayerSP layer,
if(undoAdapter) {
gc.beginTransaction(transactionText);
}
QRegion dirtyRegion = indirectlyDirtyRegion();
foreach(const QRect& rc, dirtyRegion.rects()) {
gc.bitBlt(rc.topLeft(), d->temporaryTarget, rc);
{
QMutexLocker locker(&d->dirtyRegionMutex);
gc.bitBlt(d->dirtyRegion.topLeft(), d->temporaryTarget, d->dirtyRegion);
}
d->temporaryTarget = 0;
......
......@@ -82,15 +82,6 @@ public:
const QBitArray& temporaryChannelFlags() const;
private:
/**
* Adds a dirty rect to the list of rects those should be
* merged to the layer after the indirect painting is finished
* WARNING: should be called with the lock held
*
* \see lockTemporaryTarget()
*/
void addIndirectlyDirtyRect(const QRect &rect);
QRegion indirectlyDirtyRegion();
template<class UndoAdapter>
void mergeToLayerImpl(KisLayerSP layer,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment