statistics: keep track of dirty items in double-linked list

So far the items to be recalculated in the drawing thread
had a "dirty" flag and were kept in one array par z-level.

Once the series are implemented in terms of QSGNodes, there
may lots of these items. To make this more efficient when
only one or two of these items change (e.g. highlighting due
to mouseover), keep the dirty items in a linked list.

Of course, this makes the draw first version of the chart
less efficient.

There are more fancy ways of implementing the double-linked
list, but the few ns gained in the render thread are hardly
worth it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-01-15 12:22:32 +01:00 committed by bstoeger
parent ada5e8a49d
commit faf3e7079d
4 changed files with 49 additions and 36 deletions

View file

@ -54,8 +54,8 @@ public:
QQuickWindow *w() const; // Make window available to items
QSizeF size() const;
void addQSGNode(QSGNode *node, ChartZValue z); // Must only be called in render thread!
void registerChartItem(ChartItem *item);
void unregisterChartItem(const ChartItem *item);
void registerDirtyChartItem(ChartItem &item);
void unregisterDirtyChartItem(ChartItem &item);
template <typename T, class... Args>
std::unique_ptr<T> createChartItem(Args&&... args);
@ -142,7 +142,6 @@ private:
StatsState state;
QFont titleFont;
std::unique_ptr<std::vector<ChartItem *>[]> chartItems;
std::vector<std::unique_ptr<StatsAxis>> axes;
std::unique_ptr<StatsGrid> grid;
std::vector<std::unique_ptr<StatsSeries>> series;
@ -162,6 +161,7 @@ private:
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
RootNode *rootNode;
ChartItem *firstDirtyChartItem, *lastDirtyChartItem;
};
// This implementation detail must be known to users of the class.
@ -170,7 +170,6 @@ template <typename T, class... Args>
std::unique_ptr<T> StatsView::createChartItem(Args&&... args)
{
std::unique_ptr<T> res(new T(*this, std::forward<Args>(args)...));
registerChartItem(res.get());
return res;
}