scene: fixing nested masking

For any type of masking composition may be required.

@Issue: https://github.com/Samsung/thorvg/issues/1295
This commit is contained in:
Mira Grudzinska 2023-01-01 20:05:18 +01:00 committed by Hermet Park
parent 57e3efc6ab
commit 5c59c9aa71
2 changed files with 13 additions and 2 deletions

View file

@ -25,7 +25,7 @@
/* External Class Implementation */ /* External Class Implementation */
/************************************************************************/ /************************************************************************/
Scene::Scene() : pImpl(new Impl()) Scene::Scene() : pImpl(new Impl(this))
{ {
Paint::pImpl->id = TVG_CLASS_ID_SCENE; Paint::pImpl->id = TVG_CLASS_ID_SCENE;
Paint::pImpl->method(new PaintMethod<Scene::Impl>(pImpl)); Paint::pImpl->method(new PaintMethod<Scene::Impl>(pImpl));

View file

@ -60,6 +60,11 @@ struct Scene::Impl
Array<Paint*> paints; Array<Paint*> paints;
uint8_t opacity; //for composition uint8_t opacity; //for composition
RenderMethod* renderer = nullptr; //keep it for explicit clear RenderMethod* renderer = nullptr; //keep it for explicit clear
Scene* scene = nullptr;
Impl(Scene* s) : scene(s)
{
}
~Impl() ~Impl()
{ {
@ -81,8 +86,14 @@ struct Scene::Impl
bool needComposition(uint32_t opacity) bool needComposition(uint32_t opacity)
{ {
if (opacity == 0 || paints.count == 0) return false;
//Masking may require composition (even if opacity == 255)
auto compMethod = scene->composite(nullptr);
if (compMethod != CompositeMethod::None && compMethod != CompositeMethod::ClipPath) return true;
//Half translucent requires intermediate composition. //Half translucent requires intermediate composition.
if (opacity == 255 || opacity == 0) return false; if (opacity == 255) return false;
//If scene has several children or only scene, it may require composition. //If scene has several children or only scene, it may require composition.
if (paints.count > 1) return true; if (paints.count > 1) return true;