diff --git a/mobile/components/pageitem.cpp b/mobile/components/pageitem.cpp index dc63876c8..a3a32f456 100644 --- a/mobile/components/pageitem.cpp +++ b/mobile/components/pageitem.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -37,7 +38,7 @@ #define REDRAW_TIMEOUT 250 PageItem::PageItem(QQuickItem *parent) - : QQuickPaintedItem(parent), + : QQuickItem(parent), Okular::View( QLatin1String( "PageView" ) ), m_page(nullptr), m_smooth(false), @@ -308,16 +309,27 @@ void PageItem::geometryChanged(const QRectF &newGeometry, } } -void PageItem::paint(QPainter *painter) +QSGNode * PageItem::updatePaintNode(QSGNode* node, QQuickItem::UpdatePaintNodeData* /*data*/) { - if (!m_documentItem || !m_page) { - return; + if (!window() || m_buffer.isNull()) { + delete node; + return nullptr; + } + QSGSimpleTextureNode *n = static_cast(node); + if (!n) { + n = new QSGSimpleTextureNode(); + n->setOwnsTexture(true); } - const bool setAA = m_smooth && !(painter->renderHints() & QPainter::Antialiasing); - if (setAA) { - painter->save(); - painter->setRenderHint(QPainter::Antialiasing, true); + n->setTexture(window()->createTextureFromImage(m_buffer)); + n->setRect(boundingRect()); + return n; +} + +void PageItem::paint() +{ + if (!m_documentItem || !m_page || !window()) { + return; } Observer *observer = m_isThumbnail ? m_documentItem.data()->thumbnailObserver() : m_documentItem.data()->pageviewObserver(); @@ -334,22 +346,27 @@ void PageItem::paint(QPainter *painter) const int flags = PagePainter::Accessibility | PagePainter::Highlights | PagePainter::Annotations; // Simply using the limits as described by textureSize will, at times, result in the page painter // attempting to write outside the data area, unsurprisingly resulting in a crash. - QRect limits(QPoint(0, 0), textureSize().isValid() ? textureSize() : QSize(width(), height())); + QRect limits(QPoint(0, 0), QSize(width(), height())); if(limits.width() > width()) limits.setWidth(width()); if(limits.height() > height()) limits.setHeight(height()); - QPixmap pix(width()*dpr, height()*dpr); + QSize size(width()*dpr, height()*dpr); + if (size.isNull()) { + return; + } + + QPixmap pix(size); pix.setDevicePixelRatio(dpr); QPainter p(&pix); + p.setRenderHint(QPainter::Antialiasing, m_smooth); PagePainter::paintPageOnPainter(&p, m_page, observer, flags, width(), height(), limits); p.end(); - painter->drawPixmap(QPoint(), pix); - if (setAA) { - painter->restore(); - } + m_buffer = pix.toImage(); + + update(); } //Protected slots @@ -357,7 +374,7 @@ void PageItem::delayedRedraw() { if (m_documentItem && m_page) { m_intentionalDraw = true; - update(); + paint(); } } diff --git a/mobile/components/pageitem.h b/mobile/components/pageitem.h index f70ef7cf1..00787f509 100644 --- a/mobile/components/pageitem.h +++ b/mobile/components/pageitem.h @@ -20,13 +20,15 @@ #ifndef QPAGEITEM_H #define QPAGEITEM_H -#include +#include #include +#include #include #include class QTimer; +class QSGTexture; class DocumentItem; @@ -35,7 +37,7 @@ namespace Okular { class Page; } -class PageItem : public QQuickPaintedItem, public Okular::View +class PageItem : public QQuickItem, public Okular::View { Q_OBJECT @@ -105,6 +107,7 @@ public: void setBookmarked(bool bookmarked); QStringList bookmarks() const; + void paint(); /** * loads a page bookmark and tries to ensure the bookmarked position is visible @@ -135,11 +138,11 @@ public: */ Q_INVOKABLE void removeBookmark(const QString &bookmark); - void paint(QPainter *painter) override; - void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; + QSGNode * updatePaintNode(QSGNode * , QQuickItem::UpdatePaintNodeData * ) override; + Q_SIGNALS: void flickableChanged(); void implicitWidthChanged(); @@ -171,6 +174,7 @@ private: QTimer *m_redrawTimer; QPointer m_flickable; Okular::DocumentViewport m_viewPort; + QImage m_buffer; }; #endif