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:
Hermet Park 2021-06-09 20:07:28 +09:00
parent 2d2c88b153
commit 13009657cd
3 changed files with 22 additions and 5 deletions

View file

@ -468,7 +468,7 @@ public:
* @brief Guarantees that drawing task is finished. * @brief Guarantees that drawing task is finished.
* *
* The Canvas rendering can be performed asynchronously. To make sure that rendering 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. * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
* @see Canvas::draw() * @see Canvas::draw()

View file

@ -69,7 +69,5 @@ Result Canvas::update(Paint* paint) noexcept
Result Canvas::sync() noexcept Result Canvas::sync() noexcept
{ {
if (pImpl->renderer->sync()) return Result::Success; return pImpl->sync();
return Result::InsufficientCondition;
} }

View file

@ -33,6 +33,7 @@ struct Canvas::Impl
Array<Paint*> paints; Array<Paint*> paints;
RenderMethod* renderer; RenderMethod* renderer;
bool refresh = false; //if all paints should be updated by force. bool refresh = false; //if all paints should be updated by force.
bool drawing = false; //on drawing condition?
Impl(RenderMethod* pRenderer):renderer(pRenderer) Impl(RenderMethod* pRenderer):renderer(pRenderer)
{ {
@ -46,6 +47,9 @@ struct Canvas::Impl
Result push(unique_ptr<Paint> paint) Result push(unique_ptr<Paint> paint)
{ {
//You can not push paints during rendering.
if (drawing) return Result::InsufficientCondition;
auto p = paint.release(); auto p = paint.release();
if (!p) return Result::MemoryCorruption; if (!p) return Result::MemoryCorruption;
paints.push(p); paints.push(p);
@ -66,6 +70,8 @@ struct Canvas::Impl
paints.clear(); paints.clear();
drawing = false;
return Result::Success; return Result::Success;
} }
@ -99,7 +105,7 @@ struct Canvas::Impl
Result draw() 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) { for (auto paint = paints.data; paint < (paints.data + paints.count); ++paint) {
if (!(*paint)->pImpl->render(*renderer)) return Result::InsufficientCondition; if (!(*paint)->pImpl->render(*renderer)) return Result::InsufficientCondition;
@ -107,8 +113,21 @@ struct Canvas::Impl
if (!renderer->postRender()) return Result::InsufficientCondition; if (!renderer->postRender()) return Result::InsufficientCondition;
drawing = true;
return Result::Success; 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_ */ #endif /* _TVG_CANVAS_IMPL_H_ */