common: optimize scene composition
authorHermet Park <hermetpark@gmail.com>
Thu, 25 Feb 2021 03:38:39 +0000 (12:38 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Wed, 3 Mar 2021 02:16:23 +0000 (11:16 +0900)
Scene could avoid composition if its children is only child (non scene)

This patch bring it conditionally check so as to avoid unnecesary expensive job.

@Issues: 254

src/lib/tvgPaint.cpp
src/lib/tvgPaint.h
src/lib/tvgPicture.cpp
src/lib/tvgScene.cpp
src/lib/tvgSceneImpl.h
src/lib/tvgShape.cpp

index 0d47641..fcf4111 100644 (file)
@@ -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
index 85358e0..8345e53 100644 (file)
 #include <math.h>
 #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);
index f66fb6e..f871c60 100644 (file)
@@ -28,6 +28,7 @@
 
 Picture::Picture() : pImpl(new Impl(this))
 {
+    Paint::pImpl->type = PaintType::Picture;
     Paint::pImpl->method(new PaintMethod<Picture::Impl>(pImpl));
 }
 
index 9472123..f457e05 100644 (file)
@@ -27,6 +27,7 @@
 
 Scene::Scene() : pImpl(new Impl())
 {
+    Paint::pImpl->type = PaintType::Scene;
     Paint::pImpl->method(new PaintMethod<Scene::Impl>(pImpl));
 }
 
index f8e7b9d..1d28ea5 100644 (file)
@@ -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);
index d5d6c83..e4cfb9e 100644 (file)
@@ -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<Shape::Impl>(pImpl));
 }