sw_engine: Clear buffer at the proper time.

Clear the buffer when canvas->clear() is called.

TODO: We need to add a color value parameter to clear it.
This commit is contained in:
Hermet Park 2023-11-10 09:49:45 +09:00 committed by Hermet Park
parent 0c9827a9ed
commit 66305f3e6d
7 changed files with 59 additions and 33 deletions

View file

@ -50,6 +50,8 @@ void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
{
if (!canvas || !pPicture) return;
canvas->clear(false);
auto scale = 1.0f;
if (progress > 0.875f) scale = 0.125f;

View file

@ -50,6 +50,8 @@ void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
{
if (!canvas || !pPicture) return;
canvas->clear(false);
auto scale = 1.0f;
if (progress > 0.875f) scale = 4.0f;

View file

@ -53,6 +53,8 @@ void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
{
if (!canvas) return;
canvas->clear(false);
pPicture->translate(WIDTH * progress * 0.05f, HEIGHT * progress * 0.05f);
auto before = ecore_time_get();

View file

@ -376,6 +376,13 @@ SwRenderer::~SwRenderer()
bool SwRenderer::clear()
{
if (surface) return rasterClear(surface, 0, 0, surface->w, surface->h);
return false;
}
bool SwRenderer::sync()
{
for (auto task = tasks.data; task < tasks.end(); ++task) {
if ((*task)->disposed) {
@ -389,18 +396,6 @@ bool SwRenderer::clear()
if (!sharedMpool) mpoolClear(mpool);
if (surface) {
vport.x = vport.y = 0;
vport.w = surface->w;
vport.h = surface->h;
}
return true;
}
bool SwRenderer::sync()
{
return true;
}
@ -443,7 +438,13 @@ bool SwRenderer::target(pixel_t* data, uint32_t stride, uint32_t w, uint32_t h,
bool SwRenderer::preRender()
{
return rasterClear(surface, 0, 0, surface->w, surface->h);
if (surface) {
vport.x = vport.y = 0;
vport.w = surface->w;
vport.h = surface->h;
}
return true;
}

View file

@ -42,10 +42,27 @@ struct Canvas::Impl
~Impl()
{
clear(true);
//make it sure any deffered jobs
if (renderer) renderer->sync();
clearPaints(true);
delete(renderer);
}
void clearPaints(bool free)
{
if (free) {
for (auto paint : paints) {
P(paint)->unref();
if (paint->pImpl->dispose(*renderer) && P(paint)->refCnt == 0) {
delete(paint);
}
}
paints.clear();
}
drawing = false;
}
Result push(unique_ptr<Paint> paint)
{
//You can not push paints during rendering.
@ -61,20 +78,10 @@ struct Canvas::Impl
Result clear(bool free)
{
//Clear render target before drawing
//Clear render target
if (!renderer || !renderer->clear()) return Result::InsufficientCondition;
//Free paints
if (free) {
for (auto paint : paints) {
P(paint)->unref();
if (paint->pImpl->dispose(*renderer) && P(paint)->refCnt == 0) {
delete(paint);
}
}
paints.clear();
}
drawing = false;
clearPaints(free);
return Result::Success;
}

View file

@ -128,6 +128,11 @@ TEST_CASE("Canvas update, clear and reuse", "[capiSwCanvas]")
REQUIRE(tvg_canvas_update_paint(canvas, paint) == TVG_RESULT_SUCCESS);
//negative
REQUIRE(tvg_canvas_clear(canvas, false) == TVG_RESULT_INSUFFICIENT_CONDITION);
uint32_t buffer[25];
REQUIRE(tvg_swcanvas_set_target(canvas, buffer, 5, 5, 5, TVG_COLORSPACE_ARGB8888) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_canvas_clear(canvas, false) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_canvas_destroy(canvas) == TVG_RESULT_SUCCESS);

View file

@ -89,17 +89,24 @@ TEST_CASE("Clear", "[tvgSwCanvasBase]")
auto canvas = SwCanvas::gen();
REQUIRE(canvas);
auto canvas2 = SwCanvas::gen();
REQUIRE(canvas2);
//Try 0: Clear
REQUIRE(canvas->clear() == Result::Success);
REQUIRE(canvas->clear(false) == Result::Success);
REQUIRE(canvas->clear() == Result::Success);
//Try 0: Negative
REQUIRE(canvas->clear() == Result::InsufficientCondition);
REQUIRE(canvas->clear(false) == Result::InsufficientCondition);
REQUIRE(canvas->clear() == Result::InsufficientCondition);
REQUIRE(canvas2->clear(false) == Result::Success);
REQUIRE(canvas2->clear() == Result::Success);
REQUIRE(canvas2->clear(false) == Result::Success);
REQUIRE(canvas2->clear(false) == Result::InsufficientCondition);
REQUIRE(canvas2->clear() == Result::InsufficientCondition);
REQUIRE(canvas2->clear(false) == Result::InsufficientCondition);
uint32_t buffer[100*100];
REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ARGB8888) == Result::Success);
uint32_t buffer2[100*100];
REQUIRE(canvas2->target(buffer2, 100, 100, 100, SwCanvas::Colorspace::ARGB8888) == Result::Success);
//Try 1: Push -> Clear
for (int i = 0; i < 5; ++i) {