summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/graphicsitems/qmlgraphicslistview.cpp35
-rw-r--r--src/declarative/graphicsitems/qmlgraphicstext.cpp2
-rw-r--r--tests/benchmarks/declarative/text/text.pro7
-rw-r--r--tests/benchmarks/declarative/text/tst_text.cpp155
4 files changed, 189 insertions, 10 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp
index cdb3c49..16e9d6e 100644
--- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp
@@ -181,6 +181,7 @@ public:
, highlightMoveSpeed(400), highlightResizeSpeed(400), highlightRange(QmlGraphicsListView::NoHighlightRange)
, snapMode(QmlGraphicsListView::NoSnap), overshootDist(0.0)
, footerComponent(0), footer(0), headerComponent(0), header(0)
+ , bufferMode(NoBuffer)
, ownModel(false), wrap(false), autoHighlight(true), haveHighlightRange(false)
, correctFlick(true), inFlickCorrection(false), lazyRelease(false)
{}
@@ -423,7 +424,7 @@ public:
}
}
- void refill(qreal from, qreal to);
+ void refill(qreal from, qreal to, bool doBuffer = false);
void layout();
void updateUnrequestedIndexes();
void updateUnrequestedPositions();
@@ -475,6 +476,8 @@ public:
FxListItem *footer;
QmlComponent *headerComponent;
FxListItem *header;
+ enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
+ BufferMode bufferMode;
bool ownModel : 1;
bool wrap : 1;
@@ -574,13 +577,20 @@ void QmlGraphicsListViewPrivate::releaseItem(FxListItem *item)
delete item;
}
-void QmlGraphicsListViewPrivate::refill(qreal from, qreal to)
+void QmlGraphicsListViewPrivate::refill(qreal from, qreal to, bool doBuffer)
{
Q_Q(QmlGraphicsListView);
if (!isValid() || !q->isComponentComplete())
return;
- from -= buffer;
- to += buffer;
+ qreal bufferFrom = from - buffer;
+ qreal bufferTo = to + buffer;
+ qreal fillFrom = from;
+ qreal fillTo = to;
+ if (doBuffer && (bufferMode & BufferAfter))
+ fillTo = bufferTo;
+ if (doBuffer && (bufferMode & BufferBefore))
+ fillFrom = bufferFrom;
+
int modelIndex = visibleIndex;
qreal itemEnd = visiblePos-1;
if (!visibleItems.isEmpty()) {
@@ -595,7 +605,7 @@ void QmlGraphicsListViewPrivate::refill(qreal from, qreal to)
bool changed = false;
FxListItem *item = 0;
int pos = itemEnd + 1;
- while (modelIndex < model->count() && pos <= to) {
+ while (modelIndex < model->count() && pos <= fillTo) {
//qDebug() << "refill: append item" << modelIndex;
if (!(item = createItem(modelIndex)))
break;
@@ -604,8 +614,10 @@ void QmlGraphicsListViewPrivate::refill(qreal from, qreal to)
visibleItems.append(item);
++modelIndex;
changed = true;
+ if (doBuffer) // never buffer more than one item per frame
+ break;
}
- while (visibleIndex > 0 && visibleIndex <= model->count() && visiblePos > from) {
+ while (visibleIndex > 0 && visibleIndex <= model->count() && visiblePos > fillFrom) {
//qDebug() << "refill: prepend item" << visibleIndex-1 << "current top pos" << visiblePos;
if (!(item = createItem(visibleIndex-1)))
break;
@@ -614,10 +626,12 @@ void QmlGraphicsListViewPrivate::refill(qreal from, qreal to)
item->setPosition(visiblePos);
visibleItems.prepend(item);
changed = true;
+ if (doBuffer) // never buffer more than one item per frame
+ break;
}
if (!lazyRelease || !changed) { // avoid destroying items in the same frame that we create
- while (visibleItems.count() > 1 && (item = visibleItems.first()) && item->endPosition() < from) {
+ while (visibleItems.count() > 1 && (item = visibleItems.first()) && item->endPosition() < bufferFrom) {
if (item->attached->delayRemove())
break;
//qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endPosition();
@@ -627,7 +641,7 @@ void QmlGraphicsListViewPrivate::refill(qreal from, qreal to)
releaseItem(item);
changed = true;
}
- while (visibleItems.count() > 1 && (item = visibleItems.last()) && item->position() > to) {
+ while (visibleItems.count() > 1 && (item = visibleItems.last()) && item->position() > bufferTo) {
if (item->attached->delayRemove())
break;
//qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1;
@@ -647,6 +661,8 @@ void QmlGraphicsListViewPrivate::refill(qreal from, qreal to)
if (footer)
updateFooter();
updateViewport();
+ } else if (!doBuffer && buffer && bufferMode != NoBuffer) {
+ refill(from, to, true);
}
lazyRelease = false;
}
@@ -1923,11 +1939,13 @@ void QmlGraphicsListView::viewportMoved()
if ((minY - d->_moveY.value() < height()/2 || d->flickTargetY - d->_moveY.value() < height()/2)
&& minY != d->flickTargetY)
d->flickY(-d->verticalVelocity.value());
+ d->bufferMode = QmlGraphicsListViewPrivate::BufferBefore;
} else if (d->velocityY < 0) {
const qreal maxY = maxYExtent();
if ((d->_moveY.value() - maxY < height()/2 || d->_moveY.value() - d->flickTargetY < height()/2)
&& maxY != d->flickTargetY)
d->flickY(-d->verticalVelocity.value());
+ d->bufferMode = QmlGraphicsListViewPrivate::BufferAfter;
}
}
@@ -2548,6 +2566,7 @@ void QmlGraphicsListView::animStopped()
{
Q_D(QmlGraphicsListView);
d->moveReason = QmlGraphicsListViewPrivate::Other;
+ d->bufferMode = QmlGraphicsListViewPrivate::NoBuffer;
}
QmlGraphicsListViewAttached *QmlGraphicsListView::qmlAttachedProperties(QObject *obj)
diff --git a/src/declarative/graphicsitems/qmlgraphicstext.cpp b/src/declarative/graphicsitems/qmlgraphicstext.cpp
index 03baaae..6ec72ef 100644
--- a/src/declarative/graphicsitems/qmlgraphicstext.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicstext.cpp
@@ -578,8 +578,6 @@ QSize QmlGraphicsTextPrivate::setupTextLayout(QTextLayout *layout)
Q_Q(QmlGraphicsText);
layout->setCacheEnabled(true);
- QFontMetrics fm = QFontMetrics(font);
-
int height = 0;
qreal widthUsed = 0;
qreal lineWidth = 0;
diff --git a/tests/benchmarks/declarative/text/text.pro b/tests/benchmarks/declarative/text/text.pro
new file mode 100644
index 0000000..3320f53
--- /dev/null
+++ b/tests/benchmarks/declarative/text/text.pro
@@ -0,0 +1,7 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_text
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_text.cpp
+
diff --git a/tests/benchmarks/declarative/text/tst_text.cpp b/tests/benchmarks/declarative/text/tst_text.cpp
new file mode 100644
index 0000000..5c57633
--- /dev/null
+++ b/tests/benchmarks/declarative/text/tst_text.cpp
@@ -0,0 +1,155 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QTextLayout>
+#include <QPainter>
+#include <QSize>
+#include <qmath.h>
+#include <private/qtextcontrol_p.h>
+
+class tst_text : public QObject
+{
+ Q_OBJECT
+public:
+ tst_text()
+ {
+ m_text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
+ }
+
+private slots:
+ void layout();
+ void paintLayoutToPixmap();
+ void document();
+ void paintDocToPixmap();
+
+private:
+ QString m_text;
+};
+
+QSize setupTextLayout(QTextLayout *layout)
+{
+ bool wrap = true;
+ int wrapWidth = 300;
+ layout->setCacheEnabled(true);
+
+ int height = 0;
+ qreal widthUsed = 0;
+ qreal lineWidth = 0;
+
+ //set manual width
+ if (wrap)
+ lineWidth = wrapWidth;
+
+ layout->beginLayout();
+
+ while (1) {
+ QTextLine line = layout->createLine();
+ if (!line.isValid())
+ break;
+
+ if (wrap)
+ line.setLineWidth(lineWidth);
+ }
+ layout->endLayout();
+
+ for (int i = 0; i < layout->lineCount(); ++i) {
+ QTextLine line = layout->lineAt(i);
+ widthUsed = qMax(widthUsed, line.naturalTextWidth());
+ line.setPosition(QPointF(0, height));
+ height += int(line.height());
+ }
+ return QSize(qCeil(widthUsed), height);
+}
+
+void tst_text::layout()
+{
+ //get rid of initialization effects
+ QTextLayout layout(m_text);
+ setupTextLayout(&layout);
+
+ QBENCHMARK {
+ QTextLayout layout(m_text);
+ setupTextLayout(&layout);
+ }
+}
+
+void tst_text::paintLayoutToPixmap()
+{
+ QTextLayout layout(m_text);
+ QSize size = setupTextLayout(&layout);
+
+ QBENCHMARK {
+ QPixmap img(size);
+ img.fill(Qt::transparent);
+ QPainter p(&img);
+ layout.draw(&p, QPointF(0, 0));
+ }
+}
+
+void tst_text::document()
+{
+ QTextControl *control = new QTextControl(m_text);
+
+ QBENCHMARK {
+ QTextControl *control = new QTextControl;
+ QTextDocument *doc = control->document();
+ doc->setHtml(m_text);
+ }
+}
+
+void tst_text::paintDocToPixmap()
+{
+ QTextControl *control = new QTextControl;
+ QTextDocument *doc = control->document();
+ doc->setHtml(m_text);
+ QSize size = doc->size().toSize();
+
+ QBENCHMARK {
+ QPixmap img(size);
+ img.fill(Qt::transparent);
+ QPainter p(&img);
+ control->drawContents(&p, QRectF(QPointF(0, 0), QSizeF(size)));
+ }
+}
+
+QTEST_MAIN(tst_text)
+#include "tst_text.moc"