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