GPU caching for better performance after many strokes
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 12s
Python / lint-format (pull_request) Successful in 17s
Python / test (pull_request) Successful in 31s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m6s

This commit is contained in:
2026-06-20 20:55:15 +02:00
parent 8a87f86758
commit 7be81e584e
5 changed files with 81 additions and 20 deletions
@@ -73,7 +73,18 @@ void StrokeCanvasRenderer::synchronizeData(QCanvasPainterItem *item) {
m_penColor = canvas->m_penColor;
m_penWidth = canvas->m_penWidth;
m_strokes = canvas->m_strokes;
// Only copy strokes the renderer hasn't seen yet
while (m_strokes.size() < canvas->m_strokes.size())
m_strokes.append(canvas->m_strokes[m_strokes.size()]);
// Handle clear()
if (canvas->m_strokes.isEmpty() && !m_strokes.isEmpty()) {
for (const auto &stroke : m_strokes)
if (stroke.groupId >= 0)
m_pendingGroupRemovals.append(stroke.groupId);
m_strokes.clear();
}
m_currentStroke = canvas->m_currentStroke;
m_hoverVisible = canvas->m_hoverVisible;
@@ -81,26 +92,30 @@ void StrokeCanvasRenderer::synchronizeData(QCanvasPainterItem *item) {
}
void StrokeCanvasRenderer::paint(QCanvasPainter *painter) {
for (int id : m_pendingGroupRemovals)
painter->removePathGroup(id);
m_pendingGroupRemovals.clear();
painter->clearRect(0, 0, width(), height());
for (const auto &stroke : m_strokes)
drawStroke(painter, stroke.points, stroke.color, stroke.width);
for (const auto &stroke : m_strokes) {
painter->setStrokeStyle(stroke.color);
painter->setFillStyle(stroke.color);
painter->setLineWidth(stroke.width);
painter->setLineCap(QCanvasPainter::LineCap::Round);
painter->setLineJoin(QCanvasPainter::LineJoin::Round);
drawStroke(
painter,
m_currentStroke.points,
m_currentStroke.color,
m_currentStroke.width
);
if (m_hoverVisible) {
drawDot(
painter,
m_hoverPoint,
m_penColor,
m_penWidth
);
if (stroke.path.commandsSize() == 1) {
painter->fill(stroke.path, stroke.groupId);
} else {
painter->stroke(stroke.path, stroke.groupId);
}
}
drawStroke(painter, m_currentStroke.points, m_currentStroke.color, m_currentStroke.width);
if (m_hoverVisible)
drawDot(painter, m_hoverPoint, m_penColor, m_penWidth);
}
};