From 4c0bce3fdc286d6fc85d7e08916d2b7e152cc86f Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Wed, 9 Sep 2020 10:52:45 +0900 Subject: [PATCH] sw_engine: fix shape rendering skip issue. tvg canvas must draw retained shapes for every draw call even though user missed call update() for shapes. that case canvs must draw shapes without update, it means drawing them within previous condition. --- src/lib/sw_engine/tvgSwRenderer.cpp | 37 ++++++++++++++++++----------- src/lib/sw_engine/tvgSwRenderer.h | 2 ++ test/testDirectUpdate.cpp | 9 +++++++ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/lib/sw_engine/tvgSwRenderer.cpp b/src/lib/sw_engine/tvgSwRenderer.cpp index e69aaa4e..07926b45 100644 --- a/src/lib/sw_engine/tvgSwRenderer.cpp +++ b/src/lib/sw_engine/tvgSwRenderer.cpp @@ -138,28 +138,37 @@ bool SwRenderer::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t bool SwRenderer::preRender() { - rasterClear(surface); + return rasterClear(surface); +} - //before we start rendering, we should finish all preparing tasks - for (auto task : tasks) { - task->get(); - uint8_t r, g, b, a; - if (auto fill = task->sdata->fill()) { - rasterGradientShape(surface, &task->shape, fill->id()); - } else{ - task->sdata->fill(&r, &g, &b, &a); - if (a > 0) rasterSolidShape(surface, &task->shape, r, g, b, a); - } - task->sdata->strokeColor(&r, &g, &b, &a); - if (a > 0) rasterStroke(surface, &task->shape, r, g, b, a); - } +bool SwRenderer::postRender() +{ tasks.clear(); return true; } +bool SwRenderer::render(const Shape& shape, void *data) +{ + auto task = static_cast(data); + task->get(); + + uint8_t r, g, b, a; + if (auto fill = task->sdata->fill()) { + rasterGradientShape(surface, &task->shape, fill->id()); + } else{ + task->sdata->fill(&r, &g, &b, &a); + if (a > 0) rasterSolidShape(surface, &task->shape, r, g, b, a); + } + task->sdata->strokeColor(&r, &g, &b, &a); + if (a > 0) rasterStroke(surface, &task->shape, r, g, b, a); + + return true; +} + + bool SwRenderer::dispose(TVG_UNUSED const Shape& sdata, void *data) { auto task = static_cast(data); diff --git a/src/lib/sw_engine/tvgSwRenderer.h b/src/lib/sw_engine/tvgSwRenderer.h index 35fce30f..016e4444 100644 --- a/src/lib/sw_engine/tvgSwRenderer.h +++ b/src/lib/sw_engine/tvgSwRenderer.h @@ -34,8 +34,10 @@ public: void* prepare(const Shape& shape, void* data, const RenderTransform* transform, RenderUpdateFlag flags) override; bool dispose(const Shape& shape, void *data) override; bool preRender() override; + bool postRender() override; bool target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, uint32_t cs); bool clear() override; + bool render(const Shape& shape, void *data) override; static SwRenderer* gen(); static bool init(); diff --git a/test/testDirectUpdate.cpp b/test/testDirectUpdate.cpp index 69105c32..96de6a69 100644 --- a/test/testDirectUpdate.cpp +++ b/test/testDirectUpdate.cpp @@ -9,6 +9,15 @@ void tvgDrawCmds(tvg::Canvas* canvas) { if (!canvas) return; + //Shape (for BG) + auto bg = tvg::Shape::gen(); + bg->appendRect(0, 0, WIDTH, HEIGHT, 0, 0); + + //fill property will be retained + bg->fill(255, 255, 255, 255); + + if (canvas->push(move(bg)) != tvg::Result::Success) return; + //Shape auto shape = tvg::Shape::gen();