mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
common canvas: supplement corner cases.
filled up corner cases to return the result properly. Canvas newly has a drawing condition to prevent usage-violation.
This commit is contained in:
parent
2d2c88b153
commit
13009657cd
3 changed files with 22 additions and 5 deletions
|
@ -468,7 +468,7 @@ public:
|
|||
* @brief Guarantees that drawing task is finished.
|
||||
*
|
||||
* The Canvas rendering can be performed asynchronously. To make sure that rendering is finished,
|
||||
* the sync() should be called after the draw().
|
||||
* the sync() must be called after the draw() regardless of threading.
|
||||
*
|
||||
* @return Result::Success when succeed, Result::InsufficientCondition otherwise.
|
||||
* @see Canvas::draw()
|
||||
|
|
|
@ -69,7 +69,5 @@ Result Canvas::update(Paint* paint) noexcept
|
|||
|
||||
Result Canvas::sync() noexcept
|
||||
{
|
||||
if (pImpl->renderer->sync()) return Result::Success;
|
||||
|
||||
return Result::InsufficientCondition;
|
||||
return pImpl->sync();
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ struct Canvas::Impl
|
|||
Array<Paint*> paints;
|
||||
RenderMethod* renderer;
|
||||
bool refresh = false; //if all paints should be updated by force.
|
||||
bool drawing = false; //on drawing condition?
|
||||
|
||||
Impl(RenderMethod* pRenderer):renderer(pRenderer)
|
||||
{
|
||||
|
@ -46,6 +47,9 @@ struct Canvas::Impl
|
|||
|
||||
Result push(unique_ptr<Paint> paint)
|
||||
{
|
||||
//You can not push paints during rendering.
|
||||
if (drawing) return Result::InsufficientCondition;
|
||||
|
||||
auto p = paint.release();
|
||||
if (!p) return Result::MemoryCorruption;
|
||||
paints.push(p);
|
||||
|
@ -66,6 +70,8 @@ struct Canvas::Impl
|
|||
|
||||
paints.clear();
|
||||
|
||||
drawing = false;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
|
@ -99,7 +105,7 @@ struct Canvas::Impl
|
|||
|
||||
Result draw()
|
||||
{
|
||||
if (!renderer || !renderer->preRender()) return Result::InsufficientCondition;
|
||||
if (drawing || paints.count == 0 || !renderer || !renderer->preRender()) return Result::InsufficientCondition;
|
||||
|
||||
for (auto paint = paints.data; paint < (paints.data + paints.count); ++paint) {
|
||||
if (!(*paint)->pImpl->render(*renderer)) return Result::InsufficientCondition;
|
||||
|
@ -107,8 +113,21 @@ struct Canvas::Impl
|
|||
|
||||
if (!renderer->postRender()) return Result::InsufficientCondition;
|
||||
|
||||
drawing = true;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
Result sync()
|
||||
{
|
||||
if (!drawing) return Result::InsufficientCondition;
|
||||
if (renderer->sync()) {
|
||||
drawing = false;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
return Result::InsufficientCondition;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* _TVG_CANVAS_IMPL_H_ */
|
||||
|
|
Loading…
Add table
Reference in a new issue