Commit 2b143cf8 authored by Ulf Hermann's avatar Ulf Hermann

QmlProfiler: Convert the render pass state into a pure interface

Like that we don't have to expose any private members and we don't have
to care about QSGNodes we'll never create in a render pass.

Change-Id: I4e71da24c85de8f8f73d58fc2e76dc5e82ee31ae
Reviewed-by: default avatarKai Koehne <kai.koehne@theqtcompany.com>
parent 35204e11
...@@ -45,6 +45,12 @@ struct BindingLoopsRenderPassState : public Timeline::TimelineRenderPass::State ...@@ -45,6 +45,12 @@ struct BindingLoopsRenderPassState : public Timeline::TimelineRenderPass::State
BindingLoopMaterial material; BindingLoopMaterial material;
int indexFrom; int indexFrom;
int indexTo; int indexTo;
QVector<QSGNode *> m_expandedRows;
const QVector<QSGNode *> &expandedRows() const { return m_expandedRows; }
QSGNode *m_collapsedOverlay;
QSGNode *collapsedOverlay() const { return m_collapsedOverlay; }
}; };
struct Point2DWithOffset { struct Point2DWithOffset {
...@@ -106,13 +112,13 @@ void updateNodes(const QmlProfilerRangeModel *model, int from, int to, ...@@ -106,13 +112,13 @@ void updateNodes(const QmlProfilerRangeModel *model, int from, int to,
BindlingLoopsGeometry &row = expandedPerRow[i]; BindlingLoopsGeometry &row = expandedPerRow[i];
if (row.usedVertices > 0) { if (row.usedVertices > 0) {
row.allocate(&state->material); row.allocate(&state->material);
state->expandedRows[i]->appendChildNode(row.node); state->m_expandedRows[i]->appendChildNode(row.node);
} }
} }
if (collapsed.usedVertices > 0) { if (collapsed.usedVertices > 0) {
collapsed.allocate(&state->material); collapsed.allocate(&state->material);
state->collapsedOverlay->appendChildNode(collapsed.node); state->m_collapsedOverlay->appendChildNode(collapsed.node);
} }
int rowHeight = Timeline::TimelineModel::defaultRowHeight(); int rowHeight = Timeline::TimelineModel::defaultRowHeight();
...@@ -150,25 +156,23 @@ Timeline::TimelineRenderPass::State *QmlProfilerBindingLoopsRenderPass::update( ...@@ -150,25 +156,23 @@ Timeline::TimelineRenderPass::State *QmlProfilerBindingLoopsRenderPass::update(
Q_UNUSED(stateChanged); Q_UNUSED(stateChanged);
Q_UNUSED(spacing); Q_UNUSED(spacing);
const QmlProfilerRangeModel *model = qobject_cast<const QmlProfilerRangeModel *>(
renderer->model());
BindingLoopsRenderPassState *state; BindingLoopsRenderPassState *state;
if (oldState == 0) if (oldState == 0) {
state = new BindingLoopsRenderPassState; state = new BindingLoopsRenderPassState;
else state->m_expandedRows.reserve(model->expandedRowCount());
for (int i = 0; i < model->expandedRowCount(); ++i)
state->m_expandedRows << new QSGNode;
state->m_collapsedOverlay = new QSGNode;
} else {
state = static_cast<BindingLoopsRenderPassState *>(oldState); state = static_cast<BindingLoopsRenderPassState *>(oldState);
}
const QmlProfilerRangeModel *model = qobject_cast<const QmlProfilerRangeModel *>(
renderer->model());
if (!model) if (!model)
return state; return state;
if (state->expandedRows.isEmpty()) {
state->expandedRows.reserve(model->expandedRowCount());
for (int i = 0; i < model->expandedRowCount(); ++i)
state->expandedRows << new QSGNode;
}
if (state->collapsedOverlay == 0)
state->collapsedOverlay = new QSGNode;
if (indexFrom < 0 || indexTo > model->count()) if (indexFrom < 0 || indexTo > model->count())
return state; return state;
......
...@@ -61,6 +61,11 @@ struct TimelineItemsRenderPassState : public TimelineRenderPass::State { ...@@ -61,6 +61,11 @@ struct TimelineItemsRenderPassState : public TimelineRenderPass::State {
int indexFrom; int indexFrom;
int indexTo; int indexTo;
TimelineItemsMaterial collapsedRowMaterial; TimelineItemsMaterial collapsedRowMaterial;
QVector<QSGNode *> m_expandedRows;
QVector<QSGNode *> m_collapsedRows;
const QVector<QSGNode *> &expandedRows() const { return m_expandedRows; }
const QVector<QSGNode *> &collapsedRows() const { return m_collapsedRows; }
}; };
struct OpaqueColoredPoint2DWithSize { struct OpaqueColoredPoint2DWithSize {
...@@ -208,8 +213,9 @@ static void updateNodes(int from, int to, const TimelineRenderer *renderer, ...@@ -208,8 +213,9 @@ static void updateNodes(int from, int to, const TimelineRenderer *renderer,
for (int i = 0; i < model->expandedRowCount(); ++i) { for (int i = 0; i < model->expandedRowCount(); ++i) {
TimelineItemsGeometry &row = expandedPerRow[i]; TimelineItemsGeometry &row = expandedPerRow[i];
if (row.usedVertices > 0) { if (row.usedVertices > 0) {
row.allocate(&static_cast<TimelineExpandedRowNode *>(state->expandedRows[i])->material); row.allocate(&static_cast<TimelineExpandedRowNode *>(
state->expandedRows[i]->appendChildNode(row.node); state->m_expandedRows[i])->material);
state->m_expandedRows[i]->appendChildNode(row.node);
} }
} }
...@@ -217,7 +223,7 @@ static void updateNodes(int from, int to, const TimelineRenderer *renderer, ...@@ -217,7 +223,7 @@ static void updateNodes(int from, int to, const TimelineRenderer *renderer,
TimelineItemsGeometry &row = collapsedPerRow[i]; TimelineItemsGeometry &row = collapsedPerRow[i];
if (row.usedVertices > 0) { if (row.usedVertices > 0) {
row.allocate(&state->collapsedRowMaterial); row.allocate(&state->collapsedRowMaterial);
state->collapsedRows[i]->appendChildNode(row.node); state->m_collapsedRows[i]->appendChildNode(row.node);
} }
} }
...@@ -292,13 +298,13 @@ TimelineRenderPass::State *TimelineItemsRenderPass::update(const TimelineRendere ...@@ -292,13 +298,13 @@ TimelineRenderPass::State *TimelineItemsRenderPass::update(const TimelineRendere
state->collapsedRowMaterial.setSelectedItem(selectedItem); state->collapsedRowMaterial.setSelectedItem(selectedItem);
state->collapsedRowMaterial.setSelectionColor(selectionColor); state->collapsedRowMaterial.setSelectionColor(selectionColor);
if (state->expandedRows.isEmpty()) { if (state->m_expandedRows.isEmpty()) {
state->expandedRows.reserve(model->expandedRowCount()); state->m_expandedRows.reserve(model->expandedRowCount());
state->collapsedRows.reserve(model->collapsedRowCount()); state->m_collapsedRows.reserve(model->collapsedRowCount());
for (int i = 0; i < model->expandedRowCount(); ++i) for (int i = 0; i < model->expandedRowCount(); ++i)
state->expandedRows << new TimelineExpandedRowNode; state->m_expandedRows << new TimelineExpandedRowNode;
for (int i = 0; i < model->collapsedRowCount(); ++i) for (int i = 0; i < model->collapsedRowCount(); ++i)
state->collapsedRows << new QSGNode; state->m_collapsedRows << new QSGNode;
} }
if (indexFrom < 0 || indexTo > model->count()) if (indexFrom < 0 || indexTo > model->count())
...@@ -325,7 +331,7 @@ TimelineRenderPass::State *TimelineItemsRenderPass::update(const TimelineRendere ...@@ -325,7 +331,7 @@ TimelineRenderPass::State *TimelineItemsRenderPass::update(const TimelineRendere
if (model->expanded()) { if (model->expanded()) {
for (int row = 0; row < model->expandedRowCount(); ++row) { for (int row = 0; row < model->expandedRowCount(); ++row) {
TimelineExpandedRowNode *rowNode = static_cast<TimelineExpandedRowNode *>( TimelineExpandedRowNode *rowNode = static_cast<TimelineExpandedRowNode *>(
state->expandedRows[row]); state->m_expandedRows[row]);
rowNode->material.setScale( rowNode->material.setScale(
QVector2D(spacing / parentState->scale(), QVector2D(spacing / parentState->scale(),
static_cast<qreal>(model->expandedRowHeight(row))) / static_cast<qreal>(model->expandedRowHeight(row))) /
......
...@@ -65,6 +65,11 @@ struct TimelineNotesRenderPassState : public TimelineRenderPass::State ...@@ -65,6 +65,11 @@ struct TimelineNotesRenderPassState : public TimelineRenderPass::State
NotesMaterial material; NotesMaterial material;
QSGGeometry nullGeometry; QSGGeometry nullGeometry;
QSGGeometryNode *m_collapsedOverlay;
QVector<QSGNode *> m_expandedRows;
QSGNode *collapsedOverlay() const { return m_collapsedOverlay; }
const QVector<QSGNode *> &expandedRows() const { return m_expandedRows; }
}; };
const QSGGeometry::AttributeSet &NotesGeometry::point2DWithDistanceFromTop() const QSGGeometry::AttributeSet &NotesGeometry::point2DWithDistanceFromTop()
...@@ -127,7 +132,7 @@ TimelineRenderPass::State *TimelineNotesRenderPass::update(const TimelineRendere ...@@ -127,7 +132,7 @@ TimelineRenderPass::State *TimelineNotesRenderPass::update(const TimelineRendere
collapsed << timelineIndex; collapsed << timelineIndex;
} }
QSGGeometryNode *collapsedNode = static_cast<QSGGeometryNode *>(state->collapsedOverlay); QSGGeometryNode *collapsedNode = state->m_collapsedOverlay;
if (collapsed.count() > 0) { if (collapsed.count() > 0) {
collapsedNode->setGeometry(NotesGeometry::createGeometry(collapsed, model, parentState, collapsedNode->setGeometry(NotesGeometry::createGeometry(collapsed, model, parentState,
...@@ -139,7 +144,7 @@ TimelineRenderPass::State *TimelineNotesRenderPass::update(const TimelineRendere ...@@ -139,7 +144,7 @@ TimelineRenderPass::State *TimelineNotesRenderPass::update(const TimelineRendere
} }
for (int row = 0; row < model->expandedRowCount(); ++row) { for (int row = 0; row < model->expandedRowCount(); ++row) {
QSGGeometryNode *rowNode = static_cast<QSGGeometryNode *>(state->expandedRows[row]); QSGGeometryNode *rowNode = static_cast<QSGGeometryNode *>(state->m_expandedRows[row]);
if (expanded[row].isEmpty()) { if (expanded[row].isEmpty()) {
rowNode->setGeometry(&state->nullGeometry); rowNode->setGeometry(&state->nullGeometry);
rowNode->setFlag(QSGGeometryNode::OwnsGeometry, false); rowNode->setFlag(QSGGeometryNode::OwnsGeometry, false);
...@@ -157,10 +162,10 @@ TimelineNotesRenderPassState::TimelineNotesRenderPassState(int numExpandedRows) ...@@ -157,10 +162,10 @@ TimelineNotesRenderPassState::TimelineNotesRenderPassState(int numExpandedRows)
nullGeometry(NotesGeometry::point2DWithDistanceFromTop(), 0) nullGeometry(NotesGeometry::point2DWithDistanceFromTop(), 0)
{ {
material.setFlag(QSGMaterial::Blending, true); material.setFlag(QSGMaterial::Blending, true);
expandedRows.reserve(numExpandedRows); m_expandedRows.reserve(numExpandedRows);
for (int i = 0; i < numExpandedRows; ++i) for (int i = 0; i < numExpandedRows; ++i)
expandedRows << createNode(); m_expandedRows << createNode();
collapsedOverlay = createNode(); m_collapsedOverlay = createNode();
} }
QSGGeometryNode *TimelineNotesRenderPassState::createNode() QSGGeometryNode *TimelineNotesRenderPassState::createNode()
......
...@@ -270,10 +270,10 @@ QSGNode *TimelineRenderer::updatePaintNode(QSGNode *node, UpdatePaintNodeData *u ...@@ -270,10 +270,10 @@ QSGNode *TimelineRenderer::updatePaintNode(QSGNode *node, UpdatePaintNodeData *u
const TimelineRenderPass::State *passState = state->passState(pass); const TimelineRenderPass::State *passState = state->passState(pass);
if (!passState) if (!passState)
continue; continue;
if (passState->expandedOverlay) if (passState->expandedOverlay())
state->expandedOverlayRoot()->appendChildNode(passState->expandedOverlay); state->expandedOverlayRoot()->appendChildNode(passState->expandedOverlay());
if (passState->collapsedOverlay) if (passState->collapsedOverlay())
state->collapsedOverlayRoot()->appendChildNode(passState->collapsedOverlay); state->collapsedOverlayRoot()->appendChildNode(passState->collapsedOverlay());
} }
int row = 0; int row = 0;
...@@ -281,8 +281,11 @@ QSGNode *TimelineRenderer::updatePaintNode(QSGNode *node, UpdatePaintNodeData *u ...@@ -281,8 +281,11 @@ QSGNode *TimelineRenderer::updatePaintNode(QSGNode *node, UpdatePaintNodeData *u
QSGTransformNode *rowNode = new QSGTransformNode; QSGTransformNode *rowNode = new QSGTransformNode;
for (int pass = 0; pass < d->renderPasses.length(); ++pass) { for (int pass = 0; pass < d->renderPasses.length(); ++pass) {
const TimelineRenderPass::State *passState = state->passState(pass); const TimelineRenderPass::State *passState = state->passState(pass);
if (passState && passState->expandedRows.length() > row) { if (!passState)
QSGNode *rowChildNode = passState->expandedRows[row]; continue;
const QVector<QSGNode *> &rows = passState->expandedRows();
if (rows.length() > row) {
QSGNode *rowChildNode = rows[row];
if (rowChildNode) if (rowChildNode)
rowNode->appendChildNode(rowChildNode); rowNode->appendChildNode(rowChildNode);
} }
...@@ -298,8 +301,11 @@ QSGNode *TimelineRenderer::updatePaintNode(QSGNode *node, UpdatePaintNodeData *u ...@@ -298,8 +301,11 @@ QSGNode *TimelineRenderer::updatePaintNode(QSGNode *node, UpdatePaintNodeData *u
rowNode->setMatrix(matrix); rowNode->setMatrix(matrix);
for (int pass = 0; pass < d->renderPasses.length(); ++pass) { for (int pass = 0; pass < d->renderPasses.length(); ++pass) {
const TimelineRenderPass::State *passState = state->passState(pass); const TimelineRenderPass::State *passState = state->passState(pass);
if (passState && passState->collapsedRows.length() > row) { if (!passState)
QSGNode *rowChildNode = passState->collapsedRows[row]; continue;
const QVector<QSGNode *> &rows = passState->collapsedRows();
if (rows.length() > row) {
QSGNode *rowChildNode = rows[row];
if (rowChildNode) if (rowChildNode)
rowNode->appendChildNode(rowChildNode); rowNode->appendChildNode(rowChildNode);
} }
......
...@@ -32,4 +32,28 @@ ...@@ -32,4 +32,28 @@
namespace Timeline { namespace Timeline {
const QVector<QSGNode *> &TimelineRenderPass::State::expandedRows() const
{
static const QVector<QSGNode *> empty;
return empty;
}
const QVector<QSGNode *> &TimelineRenderPass::State::collapsedRows() const
{
static const QVector<QSGNode *> empty;
return empty;
}
QSGNode *TimelineRenderPass::State::expandedOverlay() const
{
return 0;
}
QSGNode *TimelineRenderPass::State::collapsedOverlay() const
{
return 0;
}
TimelineRenderPass::~TimelineRenderPass() {}
} // namespace Timeline } // namespace Timeline
...@@ -41,16 +41,15 @@ class TimelineRenderState; ...@@ -41,16 +41,15 @@ class TimelineRenderState;
class TimelineRenderPass { class TimelineRenderPass {
public: public:
struct State { class State {
State() : expandedOverlay(0), collapsedOverlay(0) {} public:
virtual const QVector<QSGNode *> &expandedRows() const;
QVector<QSGNode *> expandedRows; virtual const QVector<QSGNode *> &collapsedRows() const;
QVector<QSGNode *> collapsedRows; virtual QSGNode *expandedOverlay() const;
QSGNode *expandedOverlay; virtual QSGNode *collapsedOverlay() const;
QSGNode *collapsedOverlay;
}; };
virtual ~TimelineRenderPass() {} virtual ~TimelineRenderPass();
virtual State *update(const TimelineRenderer *renderer, const TimelineRenderState *parentState, virtual State *update(const TimelineRenderer *renderer, const TimelineRenderState *parentState,
State *state, int indexFrom, int indexTo, bool stateChanged, State *state, int indexFrom, int indexTo, bool stateChanged,
qreal spacing) const = 0; qreal spacing) const = 0;
......
...@@ -47,24 +47,34 @@ QSGSimpleRectNode *createSelectionNode() ...@@ -47,24 +47,34 @@ QSGSimpleRectNode *createSelectionNode()
return selectionNode; return selectionNode;
} }
struct TimelineSelectionRenderPassState : public TimelineRenderPass::State {
QSGSimpleRectNode *m_expandedOverlay;
QSGSimpleRectNode *m_collapsedOverlay;
QSGNode *expandedOverlay() const { return m_expandedOverlay; }
QSGNode *collapsedOverlay() const { return m_collapsedOverlay; }
};
TimelineRenderPass::State *TimelineSelectionRenderPass::update(const TimelineRenderer *renderer, TimelineRenderPass::State *TimelineSelectionRenderPass::update(const TimelineRenderer *renderer,
const TimelineRenderState *parentState, State *state, int firstIndex, int lastIndex, const TimelineRenderState *parentState, State *oldState, int firstIndex, int lastIndex,
bool stateChanged, qreal spacing) const bool stateChanged, qreal spacing) const
{ {
Q_UNUSED(stateChanged); Q_UNUSED(stateChanged);
if (state == 0) TimelineSelectionRenderPassState *state;
state = new TimelineRenderPass::State;
if (state->expandedOverlay == 0) { if (oldState == 0) {
state->expandedOverlay = createSelectionNode(); state = new TimelineSelectionRenderPassState;
state->collapsedOverlay = createSelectionNode(); state->m_expandedOverlay = createSelectionNode();
state->m_collapsedOverlay = createSelectionNode();
} else {
state = static_cast<TimelineSelectionRenderPassState *>(oldState);
} }
const TimelineModel *model = renderer->model(); const TimelineModel *model = renderer->model();
QSGSimpleRectNode *selectionNode = static_cast<QSGSimpleRectNode *>(model->expanded() ? QSGSimpleRectNode *selectionNode = static_cast<QSGSimpleRectNode *>(model->expanded() ?
state->expandedOverlay : state->m_expandedOverlay :
state->collapsedOverlay); state->m_collapsedOverlay);
QSGSimpleRectNode *child = static_cast<QSGSimpleRectNode *>(selectionNode->firstChild()); QSGSimpleRectNode *child = static_cast<QSGSimpleRectNode *>(selectionNode->firstChild());
int selectedItem = renderer->selectedItem(); int selectedItem = renderer->selectedItem();
......
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