fix - MacOS - optimize memory utilization for "PathTool" undo feature

This commit is contained in:
Yuriy Puchkov
2020-12-06 12:25:41 +02:00
parent ca56d08c19
commit a50ebf0349
3 changed files with 29 additions and 17 deletions

View File

@@ -46,17 +46,15 @@ bool AbstractPathTool::showMousePreview() const
void AbstractPathTool::undo(QPixmap& pixmap)
{
QPainter p(&pixmap);
const int val = m_thickness + m_padding;
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
defined(Q_OS_MACX))
// On edge borders MacOS returns nullptr instead of current screen,
// it means that we cannot get devicePixelRatio for the current screen,
// so we have no choice and have to save the whole screen in the
// history.
p.drawPixmap(QPoint(0, 0), m_pixmapBackup);
// Not sure how will it work on 4k and fullHd on Linux or Windows with a
// capture of different displays with different DPI, so let it be MacOS
// specific only.
const qreal pixelRatio = pixmap.devicePixelRatio();
p.drawPixmap(backupRect(pixmap).topLeft() / pixelRatio, m_pixmapBackup);
#else
QRect area = m_backupArea + QMargins(val, val, val, val);
p.drawPixmap(area.intersected(pixmap.rect()).topLeft(), m_pixmapBackup);
p.drawPixmap(backupRect(pixmap).topLeft(), m_pixmapBackup);
#endif
}
@@ -82,18 +80,30 @@ void AbstractPathTool::thicknessChanged(const int th)
void AbstractPathTool::updateBackup(const QPixmap& pixmap)
{
m_pixmapBackup = pixmap.copy(backupRect(pixmap));
}
QRect AbstractPathTool::backupRect(const QPixmap& pixmap) const
{
const QRect& limits = pixmap.rect();
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
defined(Q_OS_MACX))
// On edge borders MacOS returns nullptr instead of current screen,
// it means that we cannot get devicePixelRatio for the current screen,
// so we have no choice and have to save the whole screen in the
// history.
m_pixmapBackup = pixmap;
// Not sure how will it work on 4k and fullHd on Linux or Windows with a
// capture of different displays with different DPI, so let it be MacOS
// specific only.
const qreal pixelRatio = pixmap.devicePixelRatio();
const int val = (m_thickness + m_padding) * pixelRatio;
QRect r = m_backupArea.normalized();
if (1 != pixelRatio) {
r.moveTo(r.topLeft() * pixelRatio);
r.setSize(r.size() * pixelRatio);
}
#else
const int val = m_thickness + m_padding;
QRect area = m_backupArea.normalized() + QMargins(val, val, val, val);
m_pixmapBackup = pixmap.copy(area);
QRect r = m_backupArea.normalized();
#endif
r += QMargins(val, val, val, val);
return r.intersected(limits);
}
void AbstractPathTool::addPoint(const QPoint& point)