From 1d978ce9fafd2658121a48288a6ddf16cfccecc6 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 8 Feb 2022 11:53:06 +0200 Subject: DocumentWidget: Fixed continuous redraw issue It was possible that the progressive rendering of runs repeatedly kept drawing the first run of the page (e.g., the top heading). It should still be investigated if a similar issue can occur in the other direction, when drawing downward. A run may exist on the bottom border of a buffer, too. --- src/gmdocument.c | 6 +++++- src/gmdocument.h | 1 + src/ui/documentwidget.c | 35 +++++++++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/gmdocument.c b/src/gmdocument.c index 38077689..5ff8c72f 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c @@ -2209,7 +2209,7 @@ const iGmRun *renderProgressive_GmDocument(const iGmDocument *d, const iGmRun *f setAnsiFlags_Text(d->theme.ansiEscapes); const iGmRun *run = first; while (isValidRun_GmDocument_(d, run)) { - if ((dir < 0 && bottom_Rect(run->visBounds) < visRangeY.start) || + if ((dir < 0 && bottom_Rect(run->visBounds) <= visRangeY.start) || (dir > 0 && top_Rect(run->visBounds) >= visRangeY.end)) { break; } @@ -2260,6 +2260,10 @@ const iString *source_GmDocument(const iGmDocument *d) { return &d->source; } +iGmRunRange runRange_GmDocument(const iGmDocument *d) { + return (iGmRunRange){ constFront_Array(&d->layout), constEnd_Array(&d->layout) }; +} + size_t memorySize_GmDocument(const iGmDocument *d) { return size_String(&d->unormSource) + size_String(&d->source) + diff --git a/src/gmdocument.h b/src/gmdocument.h index 37b99c68..0969794c 100644 --- a/src/gmdocument.h +++ b/src/gmdocument.h @@ -212,6 +212,7 @@ const iGmRun * renderProgressive_GmDocument(const iGmDocument *d, const iGmRun iInt2 size_GmDocument (const iGmDocument *); const iArray * headings_GmDocument (const iGmDocument *); /* array of GmHeadings */ const iString * source_GmDocument (const iGmDocument *); +iGmRunRange runRange_GmDocument (const iGmDocument *); size_t memorySize_GmDocument (const iGmDocument *); /* bytes */ int warnings_GmDocument (const iGmDocument *); diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 7a1cdabc..dbe29c4e 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -1656,7 +1656,6 @@ static iBool render_DocumentView_(const iDocumentView *d, iDrawContext *ctx, iBo ctx->viewPos = init_I2(left_Rect(ctx->docBounds) - left_Rect(bounds), -buf->origin); // printf(" buffer %zu: buf vis range %d...%d\n", i, bufVisRange.start, bufVisRange.end); if (!prerenderExtra && !isEmpty_Range(&bufVisRange)) { - didDraw = iTrue; if (isEmpty_Rangei(buf->validRange)) { /* Fill the required currently visible range (vis). */ const iRangei bufVisRange = intersect_Rangei(bufRange, vis); @@ -1669,26 +1668,46 @@ static iBool render_DocumentView_(const iDocumentView *d, iDrawContext *ctx, iBo extend_GmRunRange_(&meta->runsDrawn); buf->validRange = bufVisRange; // printf(" buffer %zu valid %d...%d\n", i, bufRange.start, bufRange.end); + didDraw = iTrue; } } else { /* Progressively fill the required runs. */ - if (meta->runsDrawn.start) { + if (meta->runsDrawn.start && buf->validRange.start > bufRange.start) { beginTarget_Paint(p, buf->texture); - meta->runsDrawn.start = renderProgressive_GmDocument(d->doc, meta->runsDrawn.start, - -1, iInvalidSize, - bufVisRange, - drawRun_DrawContext_, - ctx); - buf->validRange.start = bufVisRange.start; + iZap(ctx->runsDrawn); + const iGmRun *newStart = renderProgressive_GmDocument(d->doc, + meta->runsDrawn.start, + -1, + iInvalidSize, + bufVisRange, + drawRun_DrawContext_, + ctx); + if (ctx->runsDrawn.start) { + /* Something was actually drawn, so update the valid range. */ + const int newTop = top_Rect(ctx->runsDrawn.start->visBounds); + if (newTop != buf->validRange.start) { + didDraw = iTrue; +// printf("render: valid:%d->%d run:%p->%p\n", +// buf->validRange.start, newTop, +// meta->runsDrawn.start, +// ctx->runsDrawn.start); fflush(stdout); + buf->validRange.start = newTop; + } + meta->runsDrawn.start = newStart; + } } if (meta->runsDrawn.end) { beginTarget_Paint(p, buf->texture); + iZap(ctx->runsDrawn); meta->runsDrawn.end = renderProgressive_GmDocument(d->doc, meta->runsDrawn.end, +1, iInvalidSize, bufVisRange, drawRun_DrawContext_, ctx); + if (ctx->runsDrawn.start) { + didDraw = iTrue; + } buf->validRange.end = bufVisRange.end; } } -- cgit v1.2.3