Commit faf77fd0 authored by Ulf Hermann's avatar Ulf Hermann
Browse files

Timeline: Use QRgb and a lookup table for colors



It makes no sense to return a QColor as the only things we are using
are the red, green, and blue components. Furthermore, colorFromHue()
can only generate 360 different colors which we can easily cache
instead of recalculating them on each request.

This significantly reduces the time it takes to update the timeline
render nodes.

Change-Id: I7961014364a1bec5b089285148b2e6c141a6dc7d
Reviewed-by: Christian Kandeler's avatarChristian Kandeler <christian.kandeler@qt.io>
parent aaca50f7
......@@ -707,10 +707,10 @@ int NodeUpdater::updateNodes(const int from, const int to) const
if (start > end)
continue;
QColor color = m_model->color(i);
item.red = color.red();
item.green = color.green();
item.blue = color.blue();
QRgb color = m_model->color(i);
item.red = qRed(color);
item.green = qGreen(color);
item.blue = qBlue(color);
item.width = end > start ? (end - start) * m_parentState->scale() :
std::numeric_limits<float>::min();
......
......@@ -400,21 +400,20 @@ QList<const TimelineRenderPass *> TimelineModel::supportedRenderPasses() const
return passes;
}
QColor TimelineModel::colorBySelectionId(int index) const
QRgb TimelineModel::colorBySelectionId(int index) const
{
return colorByHue(selectionId(index) * TimelineModelPrivate::SelectionIdHueMultiplier);
}
QColor TimelineModel::colorByFraction(double fraction) const
QRgb TimelineModel::colorByFraction(double fraction) const
{
return colorByHue(fraction * TimelineModelPrivate::FractionHueMultiplier +
TimelineModelPrivate::FractionHueMininimum);
}
QColor TimelineModel::colorByHue(int hue) const
QRgb TimelineModel::colorByHue(int hue) const
{
return QColor::fromHsl(hue % 360, TimelineModelPrivate::Saturation,
TimelineModelPrivate::Lightness);
return TimelineModelPrivate::hueTable[hue];
}
/*!
......@@ -518,10 +517,10 @@ int TimelineModel::rowCount() const
return d->expanded ? d->expandedRowCount : d->collapsedRowCount;
}
QColor TimelineModel::color(int index) const
QRgb TimelineModel::color(int index) const
{
Q_UNUSED(index);
return QColor();
return QRgb();
}
QVariantList TimelineModel::labels() const
......@@ -613,6 +612,15 @@ int TimelineModel::prevItemByTypeId(int requestedTypeId, qint64 time, int curren
}, time, currentItem);
}
HueLookupTable::HueLookupTable() {
for (int hue = 0; hue < 360; ++hue) {
table[hue] = QColor::fromHsl(hue, TimelineModel::TimelineModelPrivate::Saturation,
TimelineModel::TimelineModelPrivate::Lightness).rgb();
}
}
const HueLookupTable TimelineModel::TimelineModelPrivate::hueTable;
int TimelineModel::TimelineModelPrivate::nextItemById(std::function<bool(int)> matchesId,
qint64 time, int currentItem) const
{
......
......@@ -88,7 +88,7 @@ public:
int rowCount() const;
// Methods which can optionally be implemented by child models.
Q_INVOKABLE virtual QColor color(int index) const;
Q_INVOKABLE virtual QRgb color(int index) const;
virtual QVariantList labels() const;
Q_INVOKABLE virtual QVariantMap details(int index) const;
Q_INVOKABLE virtual int expandedRow(int index) const;
......@@ -123,9 +123,9 @@ signals:
void displayNameChanged();
protected:
QColor colorBySelectionId(int index) const;
QColor colorByFraction(double fraction) const;
QColor colorByHue(int hue) const;
QRgb colorBySelectionId(int index) const;
QRgb colorByFraction(double fraction) const;
QRgb colorByHue(int hue) const;
int insert(qint64 startTime, qint64 duration, int selectionId);
int insertStart(qint64 startTime, int selectionId);
......
......@@ -30,8 +30,17 @@
namespace Timeline {
struct HueLookupTable {
QRgb table[360];
HueLookupTable();
QRgb operator[](int hue) const { return table[hue % 360]; }
};
class TIMELINE_EXPORT TimelineModel::TimelineModelPrivate {
public:
static const HueLookupTable hueTable;
static const int DefaultRowHeight = 30;
enum BoxColorProperties {
......
......@@ -39,7 +39,7 @@ int DebugMessagesModel::typeId(int index) const
return m_data[index].typeId;
}
QColor DebugMessagesModel::color(int index) const
QRgb DebugMessagesModel::color(int index) const
{
return colorBySelectionId(index);
}
......
......@@ -38,7 +38,7 @@ public:
DebugMessagesModel(QmlProfilerModelManager *manager, QObject *parent = 0);
int typeId(int index) const override;
QColor color(int index) const override;
QRgb color(int index) const override;
QVariantList labels() const override;
QVariantMap details(int index) const override;
int expandedRow(int index) const override;
......
......@@ -45,7 +45,7 @@ int InputEventsModel::typeId(int index) const
return selectionId(index) == Mouse ? m_mouseTypeId : m_keyTypeId;
}
QColor InputEventsModel::color(int index) const
QRgb InputEventsModel::color(int index) const
{
return colorBySelectionId(index);
}
......
......@@ -50,7 +50,7 @@ public:
void clear() override;
int typeId(int index) const override;
QColor color(int index) const override;
QRgb color(int index) const override;
QVariantList labels() const override;
QVariantMap details(int index) const override;
int expandedRow(int index) const override;
......
......@@ -61,7 +61,7 @@ int MemoryUsageModel::typeId(int index) const
return m_data[index].typeId;
}
QColor MemoryUsageModel::color(int index) const
QRgb MemoryUsageModel::color(int index) const
{
return colorBySelectionId(index);
}
......
......@@ -59,7 +59,7 @@ public:
int expandedRow(int index) const override;
int collapsedRow(int index) const override;
int typeId(int index) const override;
QColor color(int index) const override;
QRgb color(int index) const override;
float relativeHeight(int index) const override;
QVariantMap location(int index) const override;
......
......@@ -60,7 +60,7 @@ int PixmapCacheModel::typeId(int index) const
return m_data[index].typeId;
}
QColor PixmapCacheModel::color(int index) const
QRgb PixmapCacheModel::color(int index) const
{
if (m_data[index].pixmapEventType == PixmapCacheCountChanged)
return colorByHue(s_pixmapCacheCountHue);
......
......@@ -102,7 +102,7 @@ public:
int expandedRow(int index) const override;
int collapsedRow(int index) const override;
int typeId(int index) const override;
QColor color(int index) const override;
QRgb color(int index) const override;
float relativeHeight(int index) const override;
QVariantList labels() const override;
......
......@@ -137,7 +137,7 @@ int QmlProfilerAnimationsModel::collapsedRow(int index) const
return rowFromThreadId(selectionId(index));
}
QColor QmlProfilerAnimationsModel::color(int index) const
QRgb QmlProfilerAnimationsModel::color(int index) const
{
double fpsFraction = m_data[index].framerate / 60.0;
if (fpsFraction > 1.0)
......
......@@ -58,7 +58,7 @@ public:
Q_INVOKABLE int expandedRow(int index) const override;
Q_INVOKABLE int collapsedRow(int index) const override;
QColor color(int index) const override;
QRgb color(int index) const override;
float relativeHeight(int index) const override;
QVariantList labels() const override;
......
......@@ -180,7 +180,7 @@ int QmlProfilerRangeModel::bindingLoopDest(int index) const
return m_data[index].bindingLoopHead;
}
QColor QmlProfilerRangeModel::color(int index) const
QRgb QmlProfilerRangeModel::color(int index) const
{
return colorBySelectionId(index);
}
......
......@@ -62,7 +62,7 @@ public:
Q_INVOKABLE int expandedRow(int index) const override;
Q_INVOKABLE int collapsedRow(int index) const override;
int bindingLoopDest(int index) const;
QColor color(int index) const override;
QRgb color(int index) const override;
QVariantList labels() const override;
QVariantMap details(int index) const override;
......
......@@ -94,7 +94,7 @@ int SceneGraphTimelineModel::typeId(int index) const
return m_data[index].typeId;
}
QColor SceneGraphTimelineModel::color(int index) const
QRgb SceneGraphTimelineModel::color(int index) const
{
return colorBySelectionId(index);
}
......
......@@ -88,7 +88,7 @@ public:
int expandedRow(int index) const override;
int collapsedRow(int index) const override;
int typeId(int index) const override;
QColor color(int index) const override;
QRgb color(int index) const override;
QVariantList labels() const override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment