From 6ad7900a3f640190d5336152bc362f037356c589 Mon Sep 17 00:00:00 2001 From: Adam Zambrzycki Date: Wed, 6 Feb 2019 14:42:03 +0100 Subject: [PATCH] Improved big blocks rendering performance (#1166) --- src/widgets/DisassemblerGraphView.cpp | 32 +++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index 61e72eb9..892509a4 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -131,7 +131,8 @@ void DisassemblerGraphView::connectSeekChanged(bool disconn) disconnect(seekable, &CutterSeekable::seekableSeekChanged, this, &DisassemblerGraphView::onSeekChanged); } else { - connect(seekable, &CutterSeekable::seekableSeekChanged, this, &DisassemblerGraphView::onSeekChanged); + connect(seekable, &CutterSeekable::seekableSeekChanged, this, + &DisassemblerGraphView::onSeekChanged); } } @@ -521,13 +522,29 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block) } } + qreal render_offset_y = -verticalScrollBar()->value() * current_scale + unscrolled_render_offset_y; + qreal render_height = viewport()->size().height(); + // Render node text auto x = block.x + (2 * charWidth); int y = static_cast(block.y + (2 * charWidth)); for (auto &line : db.header_text.lines) { - RichTextPainter::paintRichText(&p, static_cast(x), y, block.width, charHeight, 0, line, mFontMetrics); + qreal lineYRender = y * current_scale; + qreal lineHeightRender = charHeight * current_scale; + + // Check if line does NOT intersects with view area + if (-render_offset_y >= lineYRender + lineHeightRender + || -render_offset_y + render_height <= lineYRender) { + // Skip if it does not intersects + y += charHeight; + continue; + } + + RichTextPainter::paintRichText(&p, static_cast(x), y, block.width, charHeight, 0, line, + mFontMetrics); y += charHeight; } + for (const Instr &instr : db.instrs) { if (Core()->isBreakpoint(breakpoints, instr.addr)) { p.fillRect(QRect(static_cast(block.x + charWidth), y, @@ -540,6 +557,17 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block) } } for (auto &line : instr.text.lines) { + qreal lineYRender = y * current_scale; + qreal lineHeightRender = charHeight * current_scale; + + // Check if line does NOT intersects with view area + if (-render_offset_y >= lineYRender + lineHeightRender + || -render_offset_y + render_height <= lineYRender) { + // Skip if it does not intersects + y += charHeight; + continue; + } + int rectSize = qRound(charWidth); if (rectSize % 2) { rectSize++;