QmlProfiler: rendering optimizations

Reviewed-by: Kai Koehne
This commit is contained in:
Christiaan Janssen
2011-04-05 12:49:02 +02:00
parent 4bb3d2e890
commit 80036b8905
4 changed files with 26 additions and 14 deletions

View File

@@ -49,6 +49,7 @@ TiledCanvas::TiledCanvas()
{
setFlag(QGraphicsItem::ItemHasNoContents, false);
setAcceptedMouseButtons(Qt::LeftButton);
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
}
QSizeF TiledCanvas::canvasSize() const

View File

@@ -89,6 +89,9 @@ function drawData(canvas, ctxt, region)
var sumValue = ranges[ranges.length - 1].start + ranges[ranges.length - 1].duration - ranges[0].start;
var spacing = width / sumValue;
ctxt.fillStyle = "rgba(0,0,0,1)";
var highest = [0,0,0,0,0];
//### only draw those in range
for (var ii = 0; ii < ranges.length; ++ii) {
@@ -103,8 +106,11 @@ function drawData(canvas, ctxt, region)
if (size < 0.5)
size = 0.5;
ctxt.fillStyle = "rgba(0,0,0,1)" //colors[ranges[ii].type];
xx = Math.round(xx);
if (xx + size > highest[ranges[ii].type]) {
ctxt.fillRect(xx, ranges[ii].type*10, size, 10);
highest[ranges[ii].type] = xx+size;
}
}
//draw fps overlay

View File

@@ -81,6 +81,16 @@ void TimelineView::setRanges(const QScriptValue &value)
for (int i = 0; i < m_rangeList.count(); ++i)
m_prevLimits << PrevLimits(0, 0);
qreal startValue = m_ranges.property(0).property("start").toNumber();
m_starts.clear();
m_starts.reserve(length);
m_ends.clear();
m_ends.reserve(length);
for (int i = 0; i < length; ++i) {
m_starts.append(m_ranges.property(i).property("start").toNumber() - startValue);
m_ends.append(m_ranges.property(i).property("start").toNumber() + m_ranges.property(i).property("duration").toNumber() - startValue);
}
}
void TimelineView::setStartX(qreal arg)
@@ -127,32 +137,25 @@ void TimelineView::updateTimeline(bool updateStartX)
qreal oldtw = m_totalWidth;
m_totalWidth = totalRange * spacing;
qreal offsets[length][2];
for (int i = 0; i < length; ++i) {
offsets[i][0] = (m_ranges.property(i).property("start").toNumber() - startValue);
offsets[i][1] = (m_ranges.property(i).property("start").toNumber() + m_ranges.property(i).property("duration").toNumber() - startValue);
}
// Find region samples
int minsample = 0;
int maxsample = 0;
for (int i = 0; i < length; ++i) {
if (offsets[i][1] >= m_startTime)
if (m_ends.at(i) >= m_startTime)
break;
minsample = i;
}
for (int i = minsample + 1; i < length; ++i) {
maxsample = i;
if (offsets[i][0] > m_endTime)
if (m_starts.at(i) > m_endTime)
break;
}
//### overkill (if we can expose whether or not data is nested)
for (int i = maxsample + 1; i < length; ++i) {
if (offsets[i][0] < m_endTime)
if (m_starts.at(i) < m_endTime)
maxsample = i;
}
@@ -222,8 +225,8 @@ void TimelineView::updateTimeline(bool updateStartX)
item->setParentItem(this);
}
if (item) {
item->setX(offsets[i][0]*spacing);
item->setWidth(m_ranges.property(i).property("duration").toNumber() * spacing);
item->setX(m_starts.at(i)*spacing);
item->setWidth((m_ends.at(i)-m_starts.at(i)) * spacing);
item->setZValue(++z);
}
if (creating)

View File

@@ -129,6 +129,8 @@ private:
qreal m_startX;
int prevMin;
int prevMax;
QList<qreal> m_starts;
QList<qreal> m_ends;
struct PrevLimits {
PrevLimits(int _min, int _max) : min(_min), max(_max) {}