QtQuick: remove unnecessary use of QQuickPixmapItem

It was already ported to render into a pixmap, so just pass that pixmap
as a texture.
remotes/offline-stg/wilder
Aleix Pol 8 years ago
parent 77dfe3ddc6
commit 374d953e39
  1. 47
      mobile/components/pageitem.cpp
  2. 12
      mobile/components/pageitem.h

@ -24,6 +24,7 @@
#include <QTimer> #include <QTimer>
#include <QStyleOptionGraphicsItem> #include <QStyleOptionGraphicsItem>
#include <QQuickWindow> #include <QQuickWindow>
#include <QSGSimpleTextureNode>
#include <core/bookmarkmanager.h> #include <core/bookmarkmanager.h>
#include <core/document.h> #include <core/document.h>
@ -37,7 +38,7 @@
#define REDRAW_TIMEOUT 250 #define REDRAW_TIMEOUT 250
PageItem::PageItem(QQuickItem *parent) PageItem::PageItem(QQuickItem *parent)
: QQuickPaintedItem(parent), : QQuickItem(parent),
Okular::View( QLatin1String( "PageView" ) ), Okular::View( QLatin1String( "PageView" ) ),
m_page(nullptr), m_page(nullptr),
m_smooth(false), 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) { if (!window() || m_buffer.isNull()) {
return; delete node;
return nullptr;
}
QSGSimpleTextureNode *n = static_cast<QSGSimpleTextureNode *>(node);
if (!n) {
n = new QSGSimpleTextureNode();
n->setOwnsTexture(true);
} }
const bool setAA = m_smooth && !(painter->renderHints() & QPainter::Antialiasing); n->setTexture(window()->createTextureFromImage(m_buffer));
if (setAA) { n->setRect(boundingRect());
painter->save(); return n;
painter->setRenderHint(QPainter::Antialiasing, true); }
void PageItem::paint()
{
if (!m_documentItem || !m_page || !window()) {
return;
} }
Observer *observer = m_isThumbnail ? m_documentItem.data()->thumbnailObserver() : m_documentItem.data()->pageviewObserver(); 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; 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 // 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. // 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()) if(limits.width() > width())
limits.setWidth(width()); limits.setWidth(width());
if(limits.height() > height()) if(limits.height() > height())
limits.setHeight(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); pix.setDevicePixelRatio(dpr);
QPainter p(&pix); QPainter p(&pix);
p.setRenderHint(QPainter::Antialiasing, m_smooth);
PagePainter::paintPageOnPainter(&p, m_page, observer, flags, width(), height(), limits); PagePainter::paintPageOnPainter(&p, m_page, observer, flags, width(), height(), limits);
p.end(); p.end();
painter->drawPixmap(QPoint(), pix);
if (setAA) { m_buffer = pix.toImage();
painter->restore();
} update();
} }
//Protected slots //Protected slots
@ -357,7 +374,7 @@ void PageItem::delayedRedraw()
{ {
if (m_documentItem && m_page) { if (m_documentItem && m_page) {
m_intentionalDraw = true; m_intentionalDraw = true;
update(); paint();
} }
} }

@ -20,13 +20,15 @@
#ifndef QPAGEITEM_H #ifndef QPAGEITEM_H
#define QPAGEITEM_H #define QPAGEITEM_H
#include <QQuickPaintedItem> #include <QQuickItem>
#include <QPointer> #include <QPointer>
#include <QImage>
#include <core/document.h> #include <core/document.h>
#include <core/view.h> #include <core/view.h>
class QTimer; class QTimer;
class QSGTexture;
class DocumentItem; class DocumentItem;
@ -35,7 +37,7 @@ namespace Okular {
class Page; class Page;
} }
class PageItem : public QQuickPaintedItem, public Okular::View class PageItem : public QQuickItem, public Okular::View
{ {
Q_OBJECT Q_OBJECT
@ -105,6 +107,7 @@ public:
void setBookmarked(bool bookmarked); void setBookmarked(bool bookmarked);
QStringList bookmarks() const; QStringList bookmarks() const;
void paint();
/** /**
* loads a page bookmark and tries to ensure the bookmarked position is visible * 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); Q_INVOKABLE void removeBookmark(const QString &bookmark);
void paint(QPainter *painter) override;
void geometryChanged(const QRectF &newGeometry, void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry) override; const QRectF &oldGeometry) override;
QSGNode * updatePaintNode(QSGNode * , QQuickItem::UpdatePaintNodeData * ) override;
Q_SIGNALS: Q_SIGNALS:
void flickableChanged(); void flickableChanged();
void implicitWidthChanged(); void implicitWidthChanged();
@ -171,6 +174,7 @@ private:
QTimer *m_redrawTimer; QTimer *m_redrawTimer;
QPointer<QQuickItem> m_flickable; QPointer<QQuickItem> m_flickable;
Okular::DocumentViewport m_viewPort; Okular::DocumentViewport m_viewPort;
QImage m_buffer;
}; };
#endif #endif

Loading…
Cancel
Save