diff --git a/src/lib/tvgPaint.cpp b/src/lib/tvgPaint.cpp index 0d47641c..fcf41110 100644 --- a/src/lib/tvgPaint.cpp +++ b/src/lib/tvgPaint.cpp @@ -102,4 +102,4 @@ Result Paint::opacity(uint8_t o) noexcept uint8_t Paint::opacity() const noexcept { return pImpl->opacity; -} +} \ No newline at end of file diff --git a/src/lib/tvgPaint.h b/src/lib/tvgPaint.h index 85358e00..8345e53d 100644 --- a/src/lib/tvgPaint.h +++ b/src/lib/tvgPaint.h @@ -26,9 +26,10 @@ #include #include "tvgRender.h" - namespace tvg { + enum class PaintType { Shape = 0, Scene, Picture }; + struct StrategyMethod { virtual ~StrategyMethod() {} @@ -52,6 +53,8 @@ namespace tvg uint8_t opacity = 255; + PaintType type; + ~Impl() { if (cmpTarget) delete(cmpTarget); if (smethod) delete(smethod); diff --git a/src/lib/tvgPicture.cpp b/src/lib/tvgPicture.cpp index f66fb6eb..f871c601 100644 --- a/src/lib/tvgPicture.cpp +++ b/src/lib/tvgPicture.cpp @@ -28,6 +28,7 @@ Picture::Picture() : pImpl(new Impl(this)) { + Paint::pImpl->type = PaintType::Picture; Paint::pImpl->method(new PaintMethod(pImpl)); } diff --git a/src/lib/tvgScene.cpp b/src/lib/tvgScene.cpp index 94721231..f457e059 100644 --- a/src/lib/tvgScene.cpp +++ b/src/lib/tvgScene.cpp @@ -27,6 +27,7 @@ Scene::Scene() : pImpl(new Impl()) { + Paint::pImpl->type = PaintType::Scene; Paint::pImpl->method(new PaintMethod(pImpl)); } diff --git a/src/lib/tvgSceneImpl.h b/src/lib/tvgSceneImpl.h index f8e7b9d5..1d28ea52 100644 --- a/src/lib/tvgSceneImpl.h +++ b/src/lib/tvgSceneImpl.h @@ -64,8 +64,14 @@ struct Scene::Impl { Compositor* cmp = nullptr; + //If scene has several children or only scene, it may require composition. + auto condition = false; + if ((paints.count > 1) || (paints.count == 1 && (*paints.data)->pImpl->type == PaintType::Scene)) { + condition = true; + } + //Half translucent. This condition requires intermediate composition. - if ((opacity < 255 && opacity > 0) && (paints.count > 0)) { + if ((opacity < 255 && opacity > 0) && condition) { uint32_t x, y, w, h; if (!bounds(renderer, &x, &y, &w, &h)) return false; cmp = renderer.target(x, y, w, h); diff --git a/src/lib/tvgShape.cpp b/src/lib/tvgShape.cpp index d5d6c835..e4cfb9e5 100644 --- a/src/lib/tvgShape.cpp +++ b/src/lib/tvgShape.cpp @@ -33,6 +33,7 @@ constexpr auto PATH_KAPPA = 0.552284f; Shape :: Shape() : pImpl(new Impl(this)) { + Paint::pImpl->type = PaintType::Shape; Paint::pImpl->method(new PaintMethod(pImpl)); }