Commit b323d772 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Implement lazy creation of frames when a stroke is started

Conflicts:
	krita/image/kis_transaction_data.cpp
parent 832e22e7
......@@ -29,9 +29,9 @@
//#define DEBUG_TRANSACTIONS
#ifdef DEBUG_TRANSACTIONS
#define DEBUG_ACTION(action) dbgKrita << action << "for" << m_d->device->dataManager()
# define DEBUG_ACTION(action) dbgKrita << action << "for" << m_d->device->dataManager()
#else
#define DEBUG_ACTION(action)
# define DEBUG_ACTION(action)
#endif
......@@ -54,9 +54,13 @@ public:
int transactionFrameId;
KisDataManagerSP savedDataManager;
KUndo2Command newFrameCommand;
void possiblySwitchCurrentTime();
KisDataManagerSP dataManager();
void moveDevice(const QPoint newOffset);
void tryCreateNewFrame(KisPaintDeviceSP device, int time);
};
......@@ -71,6 +75,23 @@ KisTransactionData::KisTransactionData(const KUndo2MagicString& name, KisPaintDe
saveSelectionOutlineCache();
}
#include "kis_raster_keyframe_channel.h"
void KisTransactionData::Private::tryCreateNewFrame(KisPaintDeviceSP device, int time)
{
if (!device->framesInterface()) return;
KisRasterKeyframeChannel *channel = device->keyframeChannel();
KIS_ASSERT_RECOVER(channel) { return; }
KisKeyframe *keyframe = channel->keyframeAt(time);
if (!keyframe) {
keyframe = channel->activeKeyframeAt(time).data();
channel->copyKeyframe(keyframe, time, &newFrameCommand);
}
}
void KisTransactionData::init(KisPaintDeviceSP device)
{
m_d->device = device;
......@@ -82,6 +103,9 @@ void KisTransactionData::init(KisPaintDeviceSP device)
m_d->flattenUndoCommand = 0;
m_d->transactionTime = device->defaultBounds()->currentTime();
m_d->tryCreateNewFrame(m_d->device, m_d->transactionTime);
m_d->transactionFrameId = device->framesInterface() ? device->framesInterface()->currentFrameId() : -1;
m_d->savedDataManager = m_d->transactionFrameId >= 0 ?
m_d->device->framesInterface()->frameDataManager(m_d->transactionFrameId) :
......@@ -191,6 +215,8 @@ void KisTransactionData::redo()
restoreSelectionOutlineCache(false);
m_d->newFrameCommand.redo();
DEBUG_ACTION("Redo()");
Q_ASSERT(m_d->memento);
......@@ -220,6 +246,8 @@ void KisTransactionData::undo()
m_d->possiblySwitchCurrentTime();
startUpdates();
possiblyNotifySelectionChanged();
m_d->newFrameCommand.undo();
}
void KisTransactionData::saveSelectionOutlineCache()
......
......@@ -1912,6 +1912,46 @@ void KisPaintDeviceTest::testFramesUndoRedoWithChannel()
QVERIFY(o.m_currentData == o.m_frames.begin().value());
}
#include "kis_surrogate_undo_adapter.h"
void KisPaintDeviceTest::testLazyFrameCreation()
{
const KoColorSpace *cs = KoColorSpaceRegistry::instance()->rgb8();
KisPaintDeviceSP dev = new KisPaintDevice(cs);
TestUtil::TestingTimedDefaultBounds *bounds = new TestUtil::TestingTimedDefaultBounds();
dev->setDefaultBounds(bounds);
KisRasterKeyframeChannel *channel = dev->createKeyframeChannel(KisKeyframeChannel::Content, 0);
QVERIFY(channel);
KisPaintDeviceFramesInterface *i = dev->framesInterface();
QVERIFY(i);
QCOMPARE(i->frames().size(), 1);
bounds->testingSetTime(10);
QCOMPARE(i->frames().size(), 1);
KisSurrogateUndoAdapter undoAdapter;
{
KisTransaction transaction1(dev);
transaction1.commit(&undoAdapter);
}
QCOMPARE(i->frames().size(), 2);
undoAdapter.undoAll();
QCOMPARE(i->frames().size(), 1);
undoAdapter.redoAll();
QCOMPARE(i->frames().size(), 2);
}
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/variance.hpp>
......
......@@ -71,6 +71,7 @@ private Q_SLOTS:
void testFramesLeaking();
void testFramesUndoRedo();
void testFramesUndoRedoWithChannel();
void testLazyFrameCreation();
void testCompositionAssociativity();
};
......
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