Commit 878b75d1 authored by Halla Rempt's avatar Halla Rempt

Do not create a KisPaintDevice every paintEvent

Cache the paint devices we use for rendering the color selectors
for as long as possible.
parent 8b89acd3
......@@ -43,7 +43,10 @@ namespace Acs {
{
const KoColorSpace *cacheColorSpace = converter->paintingColorSpace();
const int pixelSize = cacheColorSpace->pixelSize();
realPixelCache = new KisPaintDevice(cacheColorSpace);
if (!realPixelCache || realPixelCache->colorSpace() != cacheColorSpace) {
realPixelCache = new KisPaintDevice(cacheColorSpace);
}
KoColor color;
......@@ -58,7 +61,7 @@ namespace Acs {
// NOTE: toQImage() function of the converter copies exactBounds() only!
pixelCache = converter->toQImage(realPixelCache);
pixelCacheOffset = realPixelCache->exactBounds().topLeft() - pickRect.topLeft();
}
}
};
}
......
......@@ -74,10 +74,15 @@ void KisMyPaintShadeSelector::paintEvent(QPaintEvent *) {
// It does not matter in the end, as long as the result looks good.
// This selector was ported from MyPaint in 2010
m_realPixelCache = new KisPaintDevice(this->colorSpace());
KisPaintDeviceSP realCircleBorder = new KisPaintDevice(this->colorSpace());
if (m_cachedColorSpace != colorSpace()) {
m_realPixelCache = new KisPaintDevice(colorSpace());
m_realCircleBorder = new KisPaintDevice(colorSpace());
m_cachedColorSpace = colorSpace();
}
else {
m_realPixelCache->clear();
m_realCircleBorder->clear();
}
KConfigGroup cfg = KGlobal::config()->group("advancedColorSelector");
QString shadeMyPaintType=cfg.readEntry("shadeMyPaintType", "HSV");
......@@ -161,7 +166,7 @@ void KisMyPaintShadeSelector::paintEvent(QPaintEvent *) {
color = converter()->fromHsvF(fh, fs, fv);}
//qDebug()<<color->toQcolor();
color.setOpacity(aaFactor);
Acs::setColor(realCircleBorder, QPoint(x, y), color);
Acs::setColor(m_realCircleBorder, QPoint(x, y), color);
h = 180 + 180*atan2f(dys,-dxs)/M_PI;
v = 255*(r-s_radius)/(diag-s_radius) - 128;
......@@ -194,7 +199,7 @@ void KisMyPaintShadeSelector::paintEvent(QPaintEvent *) {
}
KisPainter gc(m_realPixelCache);
gc.bitBlt(QPoint(0,0), realCircleBorder, rect());
gc.bitBlt(QPoint(0,0), m_realCircleBorder, rect());
QPainter painter(this);
QImage renderedImage = converter()->toQImage(m_realPixelCache);
......
......@@ -27,6 +27,7 @@
#include <QImage>
#include <KoColor.h>
class KoColorSpace;
class QTimer;
......@@ -56,6 +57,8 @@ private:
QTimer* m_updateTimer;
KoColor m_lastRealColor;
KisPaintDeviceSP m_realPixelCache;
KisPaintDeviceSP m_realCircleBorder;
const KoColorSpace *m_cachedColorSpace;
};
#endif // KIS_MY_PAINT_SHADE_SELECTOR_H
......@@ -110,7 +110,14 @@ void KisShadeSelectorLine::fromString(const QString& string)
void KisShadeSelectorLine::paintEvent(QPaintEvent *)
{
m_realPixelCache = new KisPaintDevice(m_parentProxy->colorSpace());
if (m_cachedColorSpace != m_parentProxy->colorSpace()) {
m_realPixelCache = new KisPaintDevice(m_parentProxy->colorSpace());
m_cachedColorSpace = m_parentProxy->colorSpace();
}
else {
m_realPixelCache->clear();
}
int patchCount;
int patchSpacing;
......
......@@ -25,6 +25,7 @@
class KisCanvas2;
class KisShadeSelectorLineComboBox;
class KisColorSelectorBaseProxy;
class KoColorSpace;
class KisShadeSelectorLineBase : public QWidget {
public:
......@@ -75,6 +76,7 @@ private:
KoColor m_realColor;
KisPaintDeviceSP m_realPixelCache;
const KoColorSpace *m_cachedColorSpace;
bool m_gradient;
int m_patchCount;
......
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