mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
common canvas: revise clear method.
Canvas::clear() introduces a new argument "free" that deterimes freeing the retained paints. If free is true, Canvas won't delete the retained paints so that user keep paints valid. In this scenario, user must have paints pointers, free them manually or push them again to the canvas. This scenario is useful if user wants to re-organize paints order in the list or reuse them.
This commit is contained in:
parent
4de26d7c86
commit
8422e8c62b
5 changed files with 14 additions and 11 deletions
|
@ -148,7 +148,7 @@ public:
|
|||
|
||||
Result reserve(uint32_t n) noexcept;
|
||||
virtual Result push(std::unique_ptr<Paint> paint) noexcept;
|
||||
virtual Result clear() noexcept;
|
||||
virtual Result clear(bool free = true) noexcept;
|
||||
virtual Result update(Paint* paint) noexcept;
|
||||
virtual Result draw() noexcept;
|
||||
virtual Result sync() noexcept;
|
||||
|
|
|
@ -147,4 +147,4 @@ void bezSplitAt(const Bezier& cur, float at, Bezier& left, Bezier& right)
|
|||
bezSplitLeft(right, t, left);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -49,9 +49,9 @@ Result Canvas::push(unique_ptr<Paint> paint) noexcept
|
|||
}
|
||||
|
||||
|
||||
Result Canvas::clear() noexcept
|
||||
Result Canvas::clear(bool free) noexcept
|
||||
{
|
||||
return pImpl->clear();
|
||||
return pImpl->clear(free);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ struct Canvas::Impl
|
|||
|
||||
~Impl()
|
||||
{
|
||||
clear();
|
||||
clear(true);
|
||||
delete(renderer);
|
||||
}
|
||||
|
||||
|
@ -53,16 +53,19 @@ struct Canvas::Impl
|
|||
return update(p);
|
||||
}
|
||||
|
||||
Result clear()
|
||||
Result clear(bool free)
|
||||
{
|
||||
if (!renderer) return Result::InsufficientCondition;
|
||||
|
||||
//Clear render target before drawing
|
||||
if (!renderer->clear()) return Result::InsufficientCondition;
|
||||
|
||||
for (auto paint : paints) {
|
||||
paint->pImpl->dispose(*renderer);
|
||||
delete(paint);
|
||||
//free paints
|
||||
if (free) {
|
||||
for (auto paint : paints) {
|
||||
paint->pImpl->dispose(*renderer);
|
||||
delete(paint);
|
||||
}
|
||||
}
|
||||
|
||||
paints.clear();
|
||||
|
@ -79,7 +82,7 @@ struct Canvas::Impl
|
|||
//Update single paint node
|
||||
if (paint) {
|
||||
paint->pImpl->update(*renderer, nullptr, compList, RenderUpdateFlag::None);
|
||||
//Update retained all paint nodes
|
||||
//Update all retained paint nodes
|
||||
} else {
|
||||
for (auto paint: paints) {
|
||||
paint->pImpl->update(*renderer, nullptr, compList, RenderUpdateFlag::None);
|
||||
|
|
|
@ -123,7 +123,7 @@ namespace tvg
|
|||
|
||||
bool dispose(RenderMethod& renderer)
|
||||
{
|
||||
if (this->compTarget) this->compTarget->pImpl->dispose(renderer);
|
||||
if (compTarget) compTarget->pImpl->dispose(renderer);
|
||||
return smethod->dispose(renderer);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue