From 5a51a1da909a3c31e35b0577c869076cb14ef388 Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Wed, 27 Dec 2023 23:31:45 +0100 Subject: [PATCH] Painter: optimised --- uppsrc/Painter/BufferPainter.h | 4 ++-- uppsrc/Painter/Path.cpp | 2 +- uppsrc/Painter/Rasterizer.cpp | 24 ++++++++++-------------- uppsrc/Painter/Render.cpp | 23 +++++++++++++---------- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/uppsrc/Painter/BufferPainter.h b/uppsrc/Painter/BufferPainter.h index 0928235fc..6001211d4 100644 --- a/uppsrc/Painter/BufferPainter.h +++ b/uppsrc/Painter/BufferPainter.h @@ -106,7 +106,7 @@ protected: private: enum { - MOVE, LINE, QUADRATIC, CUBIC, CHAR, CLEAR + MOVE, LINE, QUADRATIC, CUBIC, CHAR }; struct LinearData { int type; @@ -192,7 +192,7 @@ private: Pointf path_min, path_max; }; - enum { BATCH_SIZE = 256 }; // must be 2^n + enum { BATCH_SIZE = 128 }; // must be 2^n Buffer paths; int path_index = 0; diff --git a/uppsrc/Painter/Path.cpp b/uppsrc/Painter/Path.cpp index 931467ed4..d8cda8a98 100644 --- a/uppsrc/Painter/Path.cpp +++ b/uppsrc/Painter/Path.cpp @@ -16,7 +16,7 @@ void BufferPainter::ClearPath() Vector& p = path_info->path.Top(); if(path_info->path.Top().GetCount() > 2048) { p.Clear(); - p.Reserve(1024); + p.Reserve(128); } else p.SetCount(0); diff --git a/uppsrc/Painter/Rasterizer.cpp b/uppsrc/Painter/Rasterizer.cpp index 58a131882..20e495a8a 100644 --- a/uppsrc/Painter/Rasterizer.cpp +++ b/uppsrc/Painter/Rasterizer.cpp @@ -46,20 +46,10 @@ void Rasterizer::Create(int cx, int cy, bool subpixel) void Rasterizer::Free() { - if(cell) { - for(int i = min_y; i <= max_y; i++) { - if(cell[i].alloc != SVO_ALLOC) { + if(cell) + for(int i = 0; i <= sz.cy; i++) + if(cell[i].alloc != SVO_ALLOC) MemoryFree(cell[i].ptr); - cell[i].alloc = SVO_ALLOC; - } - cell[i].count = 0; - } - if(cell[sz.cy].alloc != SVO_ALLOC) { // check overrun - MemoryFree(cell[sz.cy].ptr); - cell[sz.cy].alloc = SVO_ALLOC; - } - cell[sz.cy].count = 0; - } } void Rasterizer::Init() @@ -71,7 +61,13 @@ void Rasterizer::Init() void Rasterizer::Reset() { - Free(); + for(int i = min_y; i <= max_y; i++) { + if(cell[i].alloc != SVO_ALLOC) { + MemoryFree(cell[i].ptr); + cell[i].alloc = SVO_ALLOC; + } + cell[i].count = 0; + } Init(); } diff --git a/uppsrc/Painter/Render.cpp b/uppsrc/Painter/Render.cpp index c424c25a6..be9ac6241 100644 --- a/uppsrc/Painter/Render.cpp +++ b/uppsrc/Painter/Render.cpp @@ -337,6 +337,7 @@ Buffer BufferPainter::RenderPath(double width, One& ss void BufferPainter::FinishPathJob() { + PAINTER_TIMING("FinishPathJob"); if(jobcount == 0) return; { @@ -360,6 +361,7 @@ void BufferPainter::FinishPathJob() Swap(cofill, cojob); // Swap to keep allocated rasters (instead of pick) fill_job & [=] { + PAINTER_TIMING("CO FILL JOB"); int miny = ip->GetHeight() - 1; int maxy = 0; @@ -380,13 +382,13 @@ void BufferPainter::FinishPathJob() co_clear[y] = false; } + int ci = CoWork::GetWorkerIndex(); if(subpixel) { SubpixelFiller subpixel_filler; - int ci = CoWork::GetWorkerIndex(); subpixel_filler.sbuffer = ci >= 0 ? co_subpixel[ci] : subpixel; for(int i = 0; i < fillcount; i++) { CoJob& j = cofill[i]; - if(j.rasterizer.NotEmpty(y)) { + if(y >= j.rasterizer.MinY() && y <= j.rasterizer.MaxY()) { subpixel_filler.color = j.c; subpixel_filler.ss = j.ss; subpixel_filler.invert = j.attr.invert; @@ -425,22 +427,20 @@ void BufferPainter::FinishPathJob() else { SolidFiller solid_filler; SpanFiller span_filler; +// int y = ymin; for(int i = 0; i < fillcount; i++) { CoJob& j = cofill[i]; - if(j.rasterizer.NotEmpty(y)) { + if(y >= j.rasterizer.MinY() && y <= j.rasterizer.MaxY()) { Rasterizer::Filler *rg; if(j.ss) { - RGBA *lspan; - int ci = CoWork::GetWorkerIndex(); if(ci >= 0) - lspan = co_span[ci]; + span_filler.buffer = co_span[ci]; else { if(!span) span.Alloc(ip->GetWidth() + 3); - lspan = span; + span_filler.buffer = span; } span_filler.ss = j.ss; - span_filler.buffer = lspan; span_filler.alpha = j.alpha; span_filler.y = y; span_filler.t = (*ip)[y]; @@ -470,8 +470,8 @@ void BufferPainter::FinishPathJob() }; int n = maxy - miny; - if(maxy >= miny) { - if(maxy - miny > 3) { + if(n >= 0) { + if(n > 6) { std::atomic ii(0); CoDo([&] { for(;;) { @@ -494,6 +494,7 @@ void BufferPainter::FinishPathJob() void BufferPainter::Finish() { + PAINTER_TIMING("Finish"); FinishPathJob(); FinishFillJob(); if(co_clear) @@ -507,12 +508,14 @@ void BufferPainter::Finish() void BufferPainter::FillOp(const RGBA& color) { + PAINTER_TIMING("FillOp"); One none; RenderPath(FILL, none, color); } void BufferPainter::StrokeOp(double width, const RGBA& color) { + PAINTER_TIMING("StrokeOp"); One none; RenderPath(width, none, color); }